31 of #100DaysOfCode Solved LeetCode 442 – Find All Duplicates in an Array using the Cyclic Sort approach 💡 🧠 Key Insight: When elements are in the range 1 to n, we can place each number at its correct index (value → index = value - 1). If a number is already present at its correct position, it reveals a duplicate 🔍 ⚡ What I learned: • In-place array manipulation (O(1) space) • Smart index mapping techniques • Identifying patterns for Cyclic Sort problems #DSA #Cpp #LeetCode #CodingJourney #ProblemSolving #LearnInPublic
LeetCode 442: Cyclic Sort for Duplicate Detection in Array
More Relevant Posts
-
Day 38 Today I solved: Majority Element (LeetCode 169) 💡 Problem: Given an array, find the element that appears more than [n/2] times. You can assume that the majority element always exists. 💡 My Approach: I used a HashMap (frequency counting) approach: 1️⃣ Traverse the array and store frequency of each element 2️⃣ Calculate n/2 3️⃣ Iterate through the map 👉 Return the element whose frequency is greater than n/2 💡 Key Insight: The majority element will always dominate the count (> n/2), so once counted, it’s easy to identify ✅ ⚡ Complexity: Time: O(n) Space: O(n) #LeetCode #DSA #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
🚀 LeetCode 438 — Find All Anagrams in a String | Solved ✅ Solved a Medium-level problem using Sliding Window + Hashing. 🔍 Approach: Maintained a dynamic window and tracked character frequencies to efficiently detect anagrams without re-sorting. ⚡ Complexity: Time: O(n) Space: O(1) (optimized using fixed-size array) 💡 Key Learning: Optimizing from hashmap → array significantly improves performance in character-based problems. Step by step, getting better at pattern recognition 🧠 #LeetCode #DSA #SlidingWindow #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 25/100 — LeetCode Challenge Today's problem: Find Minimum in Rotated Sorted Array 🧠 Concept: Binary Search on Rotated Array 💡 Key Idea: The minimum element represents the pivot point of rotation. By comparing mid with the rightmost element, we can efficiently narrow down the search space. ⚡ Time Complexity: O(log n) 📂 Solutions Repository https://lnkd.in/gkFh2mPZ Continuing to explore how binary search can be adapted for different problem variations. #100DaysOfLeetCode #DSA #LeetCode #CodingChallenge #SoftwareEngineering
To view or add a comment, sign in
-
🚀 Day 44 – LeetCode practice update Today I solved: • Matrix Similarity After Cyclic Shifts Checked whether each row remains unchanged after k cyclic shifts without actually modifying the matrix. Used index manipulation: For left shift → compared using (j + k) % n For right shift → compared using (j - k + n) % n This helped verify similarity efficiently without performing actual shifts. Time Complexity: O(m × n) Good practice on handling cyclic shifts using index-based logic instead of brute-force operations. #LeetCode #DSA #Matrix #Arrays #ProblemSolving #CodingPractice #Consistency
To view or add a comment, sign in
-
-
Day 70/100 LeetCode Challenge 🚀 Solved Search in Rotated Sorted Array II using modified binary search. 🔍 Key Learnings: Handling duplicates in rotated arrays is tricky When nums[low] == nums[mid] == nums[high], shrink search space Maintain O(log n) average, but worst case O(n) ⚡ Result: Runtime: 0 ms (Beats 100%) All test cases passed ✅ Consistency > Motivation 💯 #Day70 #LeetCode #BinarySearch #DSA #CodingJourney
To view or add a comment, sign in
-
-
🔥 Day 171 of My LeetCode Journey Problem 112: Path Sum 💡 Problem Insight: Today’s problem was about checking whether a binary tree has a root-to-leaf path whose sum equals a target value. The key detail here is root-to-leaf — not any path. Missing that leads to wrong answers. 🧠 Concept Highlight: The solution is a clean use of DFS (recursion): Subtract the current node’s value from the target Move to left and right subtrees When you reach a leaf, check if the remaining sum is zero This ensures you explore all valid paths without unnecessary work. 💪 Key Takeaway: Tree problems often reduce to accumulating state along a path. Instead of storing paths, update the condition as you traverse. ✨ Daily Reflection: This problem reinforced how recursion naturally fits tree traversal. Once you think in terms of paths and state, the solution becomes straightforward. #Day171 #LeetCode #BinaryTree #DFS #PathSum #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
38 of #100DaysOfCode 💻 Solved LeetCode 560 – Subarray Sum Equals K using an optimized approach ⚡ 🔍 Instead of checking every subarray (O(n²)), I used Prefix Sum + HashMap to bring it down to O(n) 🧠 How it works (Mapping Logic) Keep a running sum → currSum Store frequencies of sums in a map → prefix[currSum] At each step, check: 👉 If (currSum - k) already exists in the map 👉 That means a subarray with sum = k is found ✅ Add its frequency to the count Update the map with current sum 📌 Key Takeaways ✔️ Prefix Sum pattern ✔️ HashMap for constant-time lookup ✔️ Pattern recognition > brute force ✔️ Time Complexity: O(n) #LeetCode #DSA #CodingJourney #Cpp #ProblemSolving #Tech #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 20/100 — LeetCode Challenge (Revision Day) Today I revised advanced stack-based problems: • Largest Rectangle in Histogram • Maximal Rectangle 🧠 Key Learning: Understanding how to calculate ranges using monotonic stack and transforming 2D problems into 1D solutions is a powerful technique in problem-solving. This revision phase helped strengthen both concepts and confidence. 📂 Solutions Repository https://lnkd.in/gkFh2mPZ #100DaysOfLeetCode #DSA #LeetCode #CodingChallenge #Revision
To view or add a comment, sign in
-
LeetCode POTD | Day 31 3488. Closest Equal Element Queries Today’s problem was a bit tricky and required careful handling. I first stored the indices of each element using a hashmap. Then for each query, I used binary search to find the position of the current index in the list of occurrences. From there, I checked the closest elements on both sides, while also considering the circular nature of the array. What I learned today: • Binary search can be very useful when working with sorted index lists • Always consider edge cases like circular arrays carefully • Combining preprocessing with efficient lookup makes query problems much cleaner #LeetCode #DSA #POTD #CodingJourney #ProblemSolving #DailyCodingChallenge
To view or add a comment, sign in
-
-
🚀 Day 7/100 — LeetCode Challenge Solved Search in Rotated Sorted Array II At first, it feels similar to the previous rotated array problem, but duplicates make it harder to decide which half is sorted. 💡 Key idea: 1) Normally, one half is always sorted 2) But with duplicates, we can get stuck when low == mid == high 3) In that case, we shrink the search space from both ends 4) Otherwise, identify the sorted half and proceed like binary search 👉 Small change, but big impact on logic. 🧠 Time Complexity: Average: O(log n) Worst case: O(n) (due to duplicates) 💾 Space Complexity: O(1) Learning that small edge cases can completely change how an algorithm behaves. Staying consistent. #LeetCode #DSA #100DaysOfCode #Cpp #BinarySearch #CodingJourney
To view or add a comment, sign in
-
Explore related topics
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