Day 39/60 of my LeetCode Streak 🚀 Solved today’s LeetCode problem: Problem: Find the Prefix Common Array of Two Arrays Difficulty: Medium Concepts Used: • Frequency Array • Prefix Processing • Hashing Logic • Array Traversal What I learned: • Frequency counting can simplify problems involving shared occurrences between arrays • Elegant solutions often emerge after identifying the exact event that changes the answer • Prefix-based problems usually require maintaining incremental state efficiently The key insight was realizing that a number becomes “common” exactly when its frequency reaches 2 across both arrays. 🔥 #leetcode #dsa #java #arrays #hashing #prefixsum #codingjourney
Anshika Chaurasia’s Post
More Relevant Posts
-
Day 41/60 of my LeetCode Streak 🚀 Solved today’s LeetCode problem: Problem: Find the Prefix Common Array of Two Arrays Difficulty: Medium Concepts Used: • Frequency Array • Prefix Processing • Hashing Logic • Array Traversal What I learned: • Frequency counting can simplify problems involving shared occurrences between arrays • Elegant solutions often emerge after identifying the exact event that changes the answer • Prefix-based problems usually require maintaining incremental state efficiently The key insight was realizing that a number becomes “common” exactly when its frequency reaches 2 across both arrays. 🔥 #leetcode #dsa #java #arrays #hashing #prefixsum #codingjourney
To view or add a comment, sign in
-
Day 38/60 of my LeetCode Streak 🚀 Solved today’s LeetCode problem: Problem: Minimum Common Value Difficulty: Easy Concepts Used: • Two Pointer Technique • Sorted Arrays • Space Optimization What I learned: • Sorted arrays often allow optimized traversal using two pointers • Comparing elements strategically can eliminate unnecessary checks • Choosing the right approach can reduce extra space complexity significantly The key idea was leveraging the sorted property of both arrays to efficiently find the smallest common element in linear time. 🔥 #leetcode #dsa #java #twopointers #arrays #codingjourney
To view or add a comment, sign in
-
-
Day 40/60 of my LeetCode Streak 🚀 Solved today’s LeetCode problem: Problem: Minimum Common Value Difficulty: Easy Concepts Used: • Two Pointer Technique • Sorted Arrays • Space Optimization What I learned: • Sorted arrays often allow optimized traversal using two pointers • Comparing elements strategically can eliminate unnecessary checks • Choosing the right approach can reduce extra space complexity significantly The key idea was leveraging the sorted property of both arrays to efficiently find the smallest common element in linear time. 🔥 #leetcode #dsa #java #twopointers #arrays #codingjourney
To view or add a comment, sign in
-
-
🚀 Solving LeetCode Problem | Day 18 📌 Problem: Binary Tree Postorder Traversal (LeetCode 145) 💡 Approach: Used recursive DFS traversal following the order: Left subtree Right subtree Root node The key difference from preorder and inorder traversal is that the current node is processed only after both subtrees are fully explored. ⚡ Key Learning: Tree traversals may look similar, but changing the position of a single line like: ans.add(root.val); completely changes the traversal order and output. This problem reinforced how recursion uses the call stack to naturally backtrack through the tree. ⏱ Time Complexity: O(n) 📦 Space Complexity: O(h) (where h is the height of the tree) #leetcode #dsa #java #binarytree #recursion #trees #100daysofcode
To view or add a comment, sign in
-
-
🚀 Day 57/100 – LeetCode DSA Challenge 📌 Problem: 1365. How Many Numbers Are Smaller Than the Current Number 💡 Problem Statement : Given an array nums, for each element nums[i], count how many numbers in the array are smaller than it (excluding itself). 🧠 Approach to Solve: 🔹 Brute Force Approach (Easy & Intuitive): Use two loops For each element, compare it with all others Count how many are smaller Store result in output array 🔹 Better Approach (Sorting): Create a copy of array and sort it First occurrence index of each number = its count of smaller elements Use HashMap to store value → count 📚 What I Learned Today: ✔️ How to apply nested loops for comparison problems ✔️ Importance of index-wise result storage ✔️ Difference between brute force and optimized approaches ✔️ Strengthened problem-solving thinking in arrays ✨ Every day one problem closer to success! #Day57 #100DaysOfCode #LeetCode #DSA #Java #CodingJourney #Consistency #ProblemSolving
To view or add a comment, sign in
-
-
Day 17 of solving LeetCode 🚀 Problem: Binary Tree Preorder Traversal (LeetCode 144) At first, recursion felt confusing — not because of code, but because of how it actually runs. What finally clicked for me: 👉 Preorder = Root → Left → Right 👉 Visit node first, then trust recursion to handle subtrees The key shift: Stop thinking step-by-step. Start thinking: “What does this function do for ONE node?” If I understand that, recursion handles the rest. Core logic: Add current node Recurse left Recurse right 💡 Real takeaway: Recursion is not magic — it’s just breaking a big problem into identical smaller ones. Time: O(n) #leetcode #dsa #binarytree #recursion #java #problemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
100-Day LeetCode Challenge – Day 67 Solved Isomorphic Strings on LeetCode. 📌 Approach: • Checked if both strings have equal length • Used two arrays to track character mappings • Compared last seen positions of characters • If mismatch → not isomorphic • Otherwise → valid mapping 🧠 Key Idea: Ensure a one-to-one character mapping → No two characters map to the same character → Maintain consistency using indexing ⚡ Complexity: • Time: O(n) • Space: O(1) (fixed-size arrays) #LeetCode #DSA #100DaysChallenge #Java #ProblemSolving #Consistency #Day67 #LeetCode100
To view or add a comment, sign in
-
-
🚀 Day 42 of DSA | Solved Maximum Sum of Distinct Subarrays With Length K Today’s problem was a really good combination of: ✅ Sliding Window ✅ HashMap ✅ Variable window management 🧩 Problem Solved: ✅ Maximum Sum of Distinct Subarrays With Length K 💡 What I Learned: The challenge was not just finding subarrays of size k… It was making sure all elements inside the window are distinct while also maintaining the maximum sum 🔥 🧠 Approach Used: ➡️ Use a sliding window of size k ➡️ Maintain the current window sum ➡️ Use a HashMap to track frequencies ➡️ If window size exceeds k, remove elements from the left ➡️ Only update answer when all elements are distinct 📊 Complexity: ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(k) 🧠 Big Takeaway: Sliding Window problems are starting to feel much more intuitive now. Earlier I used to think window problems were only about sums 😅 But now I’m understanding how powerful they become when combined with HashMaps and frequency tracking. Every problem is teaching a new variation of the same core pattern 🚀 #Day42 #DSA #Java #SlidingWindow #HashMap #Arrays #ProblemSolving #LeetCode #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 4 of #LeetCode60DayChallenge Today I solved Remove Element (Problem 27) – a classic in-place array manipulation problem. The task: Remove all occurrences of a given value from an array and return the count of remaining elements, without using extra space. The approach: Two-pointer technique (k pointer for placement, i pointer for traversal) Shift only non-target values to the front Achieved O(n) time and O(1) space The result: ✅ 0 ms runtime (beats 100%) ✅ Memory: 43.31 MB (beats 78.16%) Little by little, these small wins build big momentum. Consistency over intensity 💪 👉 What's your go-to strategy for in-place array problems? #LeetCode #100DaysOfCode #Java #CodingChallenge #ProblemSolving #TechJourney
To view or add a comment, sign in
-
-
🚀 Day 21/100 – LeetCode Challenge ✅ Problem: Max Consecutive Ones III (Medium) 🔗 Platform: LeetCode 💡 Approach: Sliding Window Technique Today I solved the “Max Consecutive Ones III” problem using the Sliding Window approach. 👉 Use two pointers to maintain a window 👉 Count the number of zeros inside the window 👉 If zeros become greater than k, shrink the window from the left 👉 Keep updating the maximum window length This problem helped me strengthen my understanding of sliding window patterns and how they optimize subarray problems efficiently. ⚡ Time Complexity: O(n) 📦 Space Complexity: O(1) 📘 Key Learning: Sliding Window is a powerful technique for handling contiguous subarray problems efficiently without using nested loops. #100DaysOfCode #LeetCode #Java #DSA #SlidingWindow #CodingJourney #ProblemSolving
To view or add a comment, sign in
-