Day 52/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Group Anagrams Classic hashing + string pattern. String properties: • Anagrams contain the same characters • Only the order of characters differs • Need to group similar character patterns together Key idea: Use character frequency as a unique key. Why? • Anagrams will always have identical character counts • This gives a consistent way to group strings • More efficient than sorting every string Approach: • Traverse each string in the array • Count frequency of each character (a–z) • Convert frequency array into a string key • Store strings in a HashMap based on this key • Return all grouped values Time Complexity: O(n * k) Space Complexity: O(n * k) Big takeaway: Hashing + frequency counting can replace sorting for better efficiency. Hashing patterns getting stronger day by day. 🔥 Day 52 done. #100DaysOfCode #LeetCode #DSA #Algorithms #HashMap #Strings #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
Hashing Anagrams with Frequency Counting
More Relevant Posts
-
Day 58/100 | #100DaysOfDSA 🔄🔍 Today’s problem: Search in Rotated Sorted Array A twist on Binary Search with a rotated array. Key idea: Even though the array is rotated, one half is always sorted. Approach: • Use binary search • Find mid element • Check which half is sorted (left or right) • Decide if target lies in the sorted half • Narrow the search accordingly Why it works: At every step, we eliminate half of the search space just like standard binary search. Time Complexity: O(log n) Space Complexity: O(1) Big takeaway: Understanding the structure of the problem helps adapt classic algorithms like binary search. Rotation doesn’t break order — it just shifts it. 🔥 Day 58 done. #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearch #Arrays #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 58/75 — Contiguous Array Today’s problem was about finding the maximum length of a subarray with equal number of 0s and 1s. Approach: • Convert 0 → -1 to transform the problem into finding subarray with sum = 0 • Use HashMap to store first occurrence of prefix sum • If same sum appears again → subarray between them has equal 0s and 1s Key logic: if (nums[i] == 0) sum -= 1; else sum += 1; if (map.containsKey(sum)) { maxLen = Math.max(maxLen, i - map.get(sum)); } else { map.put(sum, i); } Time Complexity: O(n) Space Complexity: O(n) A clever problem that builds strong intuition for prefix sum + hashing. 58/75 🚀 #Day58 #DSA #PrefixSum #HashMap #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
-
**Day 107 of #365DaysOfLeetCode Challenge** Today’s problem: **4Sum II (LeetCode 454)** This problem looks like brute force at first glance… but a direct 4-loop solution would be **O(n⁴)** So the real challenge is: 👉 How do we optimize using smart preprocessing? 💡 **Core Idea: Meet in the Middle** Instead of checking all 4 arrays together: 1️⃣ Compute all possible sums of `nums1 + nums2` 2️⃣ Store frequencies in a HashMap 3️⃣ For every pair in `nums3 + nums4`, look for its negative value If: `a + b + c + d = 0` Then: `a + b = -(c + d)` 📌 **Approach:** * Build map of pair sums from first two arrays * Traverse pair sums from last two arrays * Add matching frequency from map ⚡ **Time Complexity:** O(n²) ⚡ **Space Complexity:** O(n²) **What I learned today:** When brute force is too expensive, split the problem into halves. 💭 **Key Takeaway:** This pattern appears often in interviews: 👉 4Sum / KSum 👉 Pair matching 👉 Meet in the Middle 👉 HashMap frequency counting Sometimes optimization is not about faster loops… It’s about changing the way you think #LeetCode #DSA #HashMap #MeetInTheMiddle #CodingChallenge #ProblemSolving #Java #TechJourney #Consistency
To view or add a comment, sign in
-
-
Day 76/100 Completed ✅ 🚀 Solved LeetCode – Search a 2D Matrix (Java) ⚡ Implemented an optimized binary search approach by treating the 2D matrix as a flattened sorted array. Converted 1D index into 2D coordinates (row = mid / m, col = mid % m) to efficiently locate the target in O(log(m × n)) time. 🧠 Key Learnings: • Applying binary search on a 2D matrix • Converting 1D index to 2D (row & column mapping) • Reducing time complexity from O(m × n) → O(log(m × n)) • Importance of problem observation (matrix behaves like sorted array) 💯 This problem strengthened my understanding of binary search variations and how to apply it beyond simple 1D arrays. 🔗 Profile: https://lnkd.in/gaJmKdrA #leetcode #datastructures #algorithms #java #matrix #binarysearch #arrays #optimization #problemSolving #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
Day 91 of #365DaysOfLeetCode Challenge Today’s problem: **Arithmetic Slices (LeetCode 413)** An interesting problem that focuses on identifying patterns in subarrays. The goal is to count all contiguous subarrays of length ≥ 3 where the difference between consecutive elements remains constant. 💡 **Key Insight:** Instead of checking every subarray (which would be inefficient), we track the current streak of arithmetic sequences. * If the current 3 elements form an arithmetic sequence → extend the streak * Keep adding the count of valid slices ending at current index * Reset when the pattern breaks 📌 **Approach:** * Use two variables: * `curr` → counts current valid extensions * `total` → accumulates final answer * Traverse from index 2 onward * Compare consecutive differences ⚡ **Time Complexity:** O(n) ⚡ **Space Complexity:** O(1) **What I learned today:** Sometimes, problems that look like they need nested loops can be optimized using pattern tracking and dynamic accumulation. Consistency is key — 91 days down, 274 to go! #LeetCode #DSA #CodingChallenge #Java #ProblemSolving #100DaysOfCode #TechJourney
To view or add a comment, sign in
-
-
Day 9/ #100DaysOfCode Solved LeetCode 1848: Minimum Distance to the Target Element. Approach: The problem can be solved using a straightforward linear traversal. Iterate through the array and check for indices where the value equals the target. For each such index, compute the absolute difference between the current index and the given start index. Maintain a variable to track the minimum distance encountered during the traversal. Solution Insight: Initialize a variable with a large value (e.g., Integer.MAX_VALUE). Traverse the array once. Whenever the target element is found, update the minimum distance using Math.abs(i - start). Return the minimum value after the loop. Complexity: Time Complexity: O(n) Space Complexity: O(1) Result: 72/72 test cases passed with optimal runtime performance. This problem reinforces the importance of simple iteration and careful tracking of minimum values in array-based problems. #100DaysOfCode #LeetCode #DSA #Java #ProblemSolving #Algorithms
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟓𝟔 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on finding a peak element using binary search. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Find Peak Element 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 • Used binary search instead of linear scan • Compared the middle element with its next element Logic: • If nums[mid] > nums[mid + 1] → peak lies on the left side (including mid) • Else → peak lies on the right side • Continued until left == right 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • Binary search can be applied on patterns, not just sorted arrays • A peak always exists due to problem constraints • Comparing adjacent elements helps determine direction • Reducing the search space is the key idea 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(log n) • Space: O(1) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Binary search is not about sorted arrays — it’s about eliminating half of the search space using logic. 56 days consistent 🚀 On to Day 57. #DSA #Arrays #BinarySearch #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
✨ Day 42 of 90 – Pattern Mastery Journey 🧠 Pattern : Alphabet Hash Pattern 💡 Approach: ✔ Created an n × n matrix using nested loops ✔ Printed alphabets only when row index equals column index (i == j) ✔ Filled all other positions with `#` ✔ Used ASCII logic `(char)('A' + i - 1)` to generate characters 🚀 This problem helped me understand how **diagonal conditions work in matrices** and how simple conditions can create clean structured patterns. #PatternMasteryJourney #Java #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 56/100 | #100DaysOfDSA 🧠⚡ Today’s problem: String Compression A clean in-place array manipulation problem. Core idea: Compress consecutive repeating characters and store the result in the same array. Approach: • Traverse the array using a pointer • Count consecutive occurrences of each character • Write the character to the array • If count > 1 → write its digits one by one • Move forward and repeat Key insight: We don’t need extra space — just carefully manage read & write pointers. Time Complexity: O(n) Space Complexity: O(1) Big takeaway: In-place algorithms require precise pointer control but give optimal space efficiency. Mastering these improves real-world memory optimization skills. 🔥 Day 56 done. #100DaysOfCode #LeetCode #DSA #Algorithms #Strings #TwoPointers #InPlace #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 61/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Median of Two Sorted Arrays A classic hard problem with a clever binary search approach. Problem idea: Find the median of two sorted arrays without fully merging them. Key idea: Use binary search on the smaller array to partition both arrays. Why? • We want left half and right half to be balanced • All elements in left ≤ all elements in right How it works: • Pick a cut in array1 • Derive cut in array2 • Check partition validity using boundary elements If valid → we found the median If not → adjust the partition Time Complexity: O(log(min(m, n))) Space Complexity: O(1) Big takeaway: Binary search isn’t just for searching — it can be used to optimize partitions and positions. This one really builds intuition. 🔥 Day 61 done. #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearch #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
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