📌 Day 13/100 - Valid Anagram (LeetCode 242) 🔹 Problem: Given two strings s and t, determine whether t is an anagram of s. An anagram is formed by rearranging the letters of one word to create another word — meaning both strings must have the same characters with the same frequency. 🔹 Approach: First, check if both strings are of equal length — if not, they can’t be anagrams. Convert both strings into character arrays. Sort both arrays and compare them using Arrays.equals(). If both sorted arrays are identical, the strings are anagrams. 🔹 Key Learning: Sorting can simplify comparison-based string problems. Always check base conditions (like length) to avoid unnecessary computation. This approach has a time complexity of O(n log n) due to sorting, which is efficient enough for this problem. Every solved challenge is another letter added to the dictionary of progress! 🚀 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #Consistency
How to check if two strings are anagrams in Java
More Relevant Posts
-
📌 Day 14/100 - Group Anagrams (LeetCode 49) 🔹 Problem: Given an array of strings, group the anagrams together. An anagram is a word formed by rearranging the letters of another — like “eat”, “tea”, and “ate”. 🔹 Approach: Traverse through each word in the array. Sort its characters alphabetically to form a key. Use a HashMap to group words with the same key. Return all grouped lists as the final result. 🔹 Key Learning: ✅ Sorting helps identify similar string patterns. ✅ HashMaps make grouping efficient and clean. ✅ Small logical steps lead to elegant solutions. Consistent effort turns complexity into clarity 💪 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #LearningEveryday
To view or add a comment, sign in
-
-
📌 Day 2/100 – Remove Element (LeetCode 27) 🔹 Problem: Given an integer array nums and a value val, remove all instances of that value in-place and return the new length of the array. The order of elements can be changed. 🔹 Approach: Used the two-pointer technique to efficiently modify the array in-place. One pointer iterates through the array, while the other tracks the position to overwrite non-val elements. Returned the position of the second pointer as the new length. 🔹 Key Learning: Strengthened understanding of in-place array manipulation. Improved logic building for pointer movement and conditional overwriting. Learned how to minimize extra space usage while maintaining readability and clarity. Another small yet powerful step toward mastering array-based problems! 💻 🔥 #100DaysOfCode #LeetCode #Java #ProblemSolving #TwoPointers #DSA #CodingJourney
To view or add a comment, sign in
-
-
23/30 days✅ Solved LeetCode Problem : #70 – Climbing Stairs The challenge was to determine how many distinct ways one can reach the top of a staircase with n steps, where at each step you can either climb 1 or 2 steps. The logic behind the problem is similar to the Fibonacci sequence, where each state depends on the sum of the previous two states. I implemented the solution in Java, using an iterative approach with three variables to optimize space complexity. Instead of using recursion or an array, the approach updates values in constant space (O(1)) while maintaining linear time complexity (O(n)). Here’s the logic in brief: Initialize a = 0, b = 1, and c = 1. For each step, compute c = a + b, then shift values forward (a = b, b = c). Return c as the total number of distinct ways to reach the top. #LeetCode #Java #DynamicProgramming #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
📌 Day 16/100 - Reverse String (LeetCode 344) 🔹 Problem: Reverse a given string in-place — meaning you must modify the original array of characters without using extra space. 🔹 Approach: Used the two-pointer technique — one starting at the beginning and one at the end of the array. Swap characters at both pointers, then move them closer until they meet. Efficient, clean, and runs in linear time without additional memory allocation. 🔹 Key Learnings: In-place algorithms optimize space complexity significantly. The two-pointer pattern is a versatile tool for many array and string problems. Understanding mutable vs immutable structures in Java is crucial for memory efficiency. Sometimes, the simplest logic beats the most complex one. 🧠 “True efficiency lies in simplicity, not complexity.” #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #TwoPointers
To view or add a comment, sign in
-
-
📌 Day 11/100 – Longest Common Prefix (LeetCode 14) 🔹 Problem: Given an array of strings, find the longest common prefix shared among them. If no common prefix exists, return an empty string. 🔹 Approach: I first sorted the array of strings in alphabetical order. The idea is that only the first and last strings in the sorted order will differ the most — so the common prefix between them is also the prefix for the entire array. I then compared characters one by one between these two strings to extract the prefix efficiently. 🔹 Key Learning: Sorting simplifies comparison by aligning similar prefixes together. Smart observation can reduce unnecessary iterations. Sometimes, the most optimal logic lies in choosing the right perspective. Step by step, improving problem-solving clarity and confidence 💪 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #LearnByDoing #CodingChallenge
To view or add a comment, sign in
-
-
📌 Day 12/100 - Concatenation of Array (LeetCode 1929) 🔹 Problem: Given an integer array nums, create a new array ans such that: ans[i] = nums[i] ans[i + n] = nums[i] where n is the length of nums. In short, we need to concatenate the array with itself to form a new array of size 2n. 🔹 Approach: First, determine the length n of the array. Create a new array newArray of size 2n. Loop through nums once: Assign each element twice — once at position i and once at position i + n. Finally, return the concatenated array. 🔹 Key Learning: Reinforced the concept of array indexing and iteration. Practiced efficient array manipulation in Java. Sometimes, the simplest logic is the cleanest — clarity beats complexity! 💡 Every solved problem adds a layer of confidence and consistency 💪 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #LearnByDoing
To view or add a comment, sign in
-
-
🚀 Day 25 of 100 Days of LeetCode 📘 Problem: Remove Nth Node from End of List 💻 Language: Java ✅ Status: Accepted — Runtime: 0 ms ⚡ (Beats 100%) Today’s challenge was about working with Linked Lists, one of the most fundamental yet tricky data structures in DSA. The problem required removing the Nth node from the end — which tested how well I could use two-pointer techniques efficiently. ✨ Key Learnings: The two-pointer approach simplifies traversal logic beautifully 🎯 Dummy nodes are game-changers for clean code and edge case handling Linked Lists demand visualization — drawing it out helps a lot! Every accepted solution sharpens my ability to reason through edge cases and optimize thought flow 🔄 #Day25 #100DaysOfCode #LeetCode #Java #LinkedList #ProblemSolving #CodingJourney #DSA #SoftwareDevelopment #CodeEveryday #KeepLearning
To view or add a comment, sign in
-
-
#Day_28 Today’s problem was quite an interesting one — “Reach a Target Number” using minimal moves. 💡 Problem Summary: Starting from 0, on each move i, you can go either left or right by i steps. The goal is to find the minimum number of moves required to reach a given target. At first glance, it looked like a simple math problem, but the trick was to notice the parity condition — once the cumulative sum goes beyond the target, the difference (sum - target) must be even to allow flipping directions and still land exactly on target. Here’s the optimized logic I implemented in Java Key Takeaway: Sometimes, problems that look complex are just about observing patterns in numbers rather than brute force. A touch of math can simplify the entire logic! #100DaysOfCode #LeetCode #CodingChallenge #Java #ProblemSolving #DSA #LearnEveryday #CodingJourney
To view or add a comment, sign in
-
-
🌟 Day 94 of 100 Days of Code 🌟 Today’s challenge: Maximum Number of Operations to Move Ones to the End (LeetCode 3228) 💡 🧠 Problem: Given a binary string, you can repeatedly move '1' to the right (until it meets another '1' or the end). The goal is to find the maximum number of such operations possible. ⚙️ Approach: Traverse the string once. Track the count of '1's and increment operations based on '10' patterns. Efficient O(n) solution using simple logic and character comparisons. ✅ Result: ✔️ All test cases passed ⚡ Runtime: 7 ms — Beats 78.52% of Java submissions #100DaysOfCode #Day94 #LeetCode #Java #ProblemSolving #CodingJourney #DataStructures #Algorithms #CodeEveryday
To view or add a comment, sign in
-
-
🌟 Day 73 of 100 Days of Challenge 🌟 📌 LeetCode 220 — Contains Duplicate III Difficulty: 🟥 Hard | Language: Java ☕ Today’s problem was a tricky combination of index range and value range checks. The task was to determine if there exists a pair (i, j) such that: i ≠ j |i - j| ≤ indexDiff |nums[i] - nums[j]| ≤ valueDiff 🧠 Key Insight Instead of brute force (which is O(n²) ❌), we can use a sliding window + TreeSet approach: Maintain a window of size indexDiff. For each nums[i], find if there’s a number within [nums[i] - valueDiff, nums[i] + valueDiff]. TreeSet’s ceiling() function helps in efficient range searching. Slide the window forward by removing older elements. ⏱ Time Complexity: O(n log k) 💾 Space Complexity: O(k) where k = indexDiff ✨ Takeaway: This problem beautifully combines data structures (TreeSet) with sliding window, making it a great practice for hard-level problems. It sharpened my ability to handle both value-based and index-based constraints efficiently. #100DaysOfCode #Day71 #DSA #LeetCode #Java #ProblemSolving #TreeSet #SlidingWindow #CodingChallenge #HardProblem #LearningEveryday
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development