Day 16/30 – Sort Colors 🚀 Solved: Sort an array of 0s, 1s, and 2s in-place. Technique Used: Dutch National Flag Algorithm 🇳🇱 Pointers: • low → boundary for 0 • mid → current element • high → boundary for 2 Single pass. Constant space. Pure pointer manipulation. Time Complexity: O(n) Space Complexity: O(1) This problem is a masterclass in two-pointer control. #30DaysOfCode #Java #DSA #TwoPointers #InterviewPrep
Sort 0s, 1s, 2s in-place with Dutch National Flag Algorithm
More Relevant Posts
-
Day 16/100 – LeetCode Challenge Problem: Merge Sorted Array Today’s problem involved merging two sorted arrays into one sorted array. Approach: Created a temporary array of size m + n Used two pointers to compare elements from both arrays Inserted the smaller element into the new array Copied remaining elements if any array still had values Finally copied the merged result back into nums1 Complexity: Time: O(m + n) Space: O(m + n) Concepts Practiced: Two-pointer technique Array traversal Merging sorted arrays #100DaysOfCode #LeetCode #DSA #Java #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 44 of DSA 🚀 Solved Minimum Number of Flips to Make the Binary String Alternating. 💡 Key Insight: An alternating binary string can only follow two patterns: 010101... 101010... To handle rotations efficiently: Double the string (s + s) Use a sliding window of size n Count mismatches with both patterns Track the minimum flips required. ⏱ Time: O(n) 💾 Space: O(n) Good practice for sliding window + pattern matching. #DSA #Java #LeetCode #100DaysOfCode
To view or add a comment, sign in
-
-
🔥 Day 83 of my LeetCode Journey 🔥 📘 Problem: 350. Intersection of Two Arrays II 🎯 Difficulty: Easy 🔹 Problem Statement: Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays, and you may return the result in any order. 🔹 Approach Used: Sort both arrays Use two pointers to traverse both arrays Compare elements: If equal → add to result and move both pointers If smaller → move that pointer forward Store results and return the intersection array 🔹 Key Concepts: Two-pointer technique Sorting arrays Efficient traversal Handling duplicates 🔹 Learning: This problem highlights how sorting combined with the two-pointer approach simplifies comparison problems. It also reinforces handling duplicates correctly while maintaining efficiency. #LeetCode #Day80 #Java #Arrays #TwoPointers #Sorting #DSA #ProblemSolving
To view or add a comment, sign in
-
-
🧠 Day 32 / 100 – DSA Practice Solved Symmetric Tree on LeetCode 🌳✅ 🔹 Problem: Check whether a binary tree is a mirror of itself (symmetric around its center). 🔹 Approach: Used a recursive mirror check: Compare left subtree with right subtree Check if: ✔️ Values are equal ✔️ Left of one == Right of other ✔️ Right of one == Left of other 🔁 Recursively verified symmetry at each level 🔹 Complexity: ⏱ Time → O(n) 📦 Space → O(n) (recursion stack) 💯 Result: ✔️ All test cases passed ⚡ Runtime: 0 ms (Beats 100%) Understanding recursion patterns in trees is getting stronger day by day 🚀 #Day32 #100DaysOfCode #LeetCode #Java #DSA #BinaryTree #Recursion #CodingJourney
To view or add a comment, sign in
-
-
Day 87/100 – LeetCode Challenge ✅ Problem: #867 Transpose Matrix Difficulty: Easy Language: Java Approach: Direct Matrix Swapping Time Complexity: O(m × n) Space Complexity: O(m × n) for result matrix Key Insight: Transpose swaps rows and columns: transposed[i][j] = matrix[j][i]. New matrix dimensions: col × row (original dimensions swapped). Solution Brief: Created result matrix with dimensions col × row. Nested loops assign each element to swapped position. Returned transposed matrix. #LeetCode #Day87 #100DaysOfCode #Matrix #Java #Algorithm #CodingChallenge #ProblemSolving #TransposeMatrix #EasyProblem #Array #2DArray #DSA
To view or add a comment, sign in
-
-
🚀 Day 35 of #100DaysOfCode 🌱 Topic: Arrays / HashSet ✅ Problem Solved: LeetCode 349 – Intersection of Two Arrays 🛠 Approach: Used a HashSet to efficiently track elements from the first array. Inserted all elements of nums1 into a HashSet. Traversed nums2 and checked if the element exists in the set. If present, added it to the result list and removed it from the set to ensure uniqueness. #100DaysOfCode #Day35 #DSA #Arrays #HashSet #LeetCode #Java #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🧠 Day 168 — Alternating Binary String 🔁⚡ Today solved a clean string pattern problem: Minimum Changes to Make Alternating Binary String. 📌 Problem Goal Given a binary string, determine the minimum number of flips needed to make it alternating. Valid alternating patterns can only be: 010101... 101010... So the trick is simply to check both possibilities. 🔹 Approach ✔️ Traverse the string once ✔️ Count mismatches assuming pattern 0101... ✔️ Count mismatches assuming pattern 1010... ✔️ Return the minimum of the two counts 🧠 Key Learning ✔️ Many string problems reduce to pattern validation ✔️ Always check all possible valid patterns ✔️ Simple logic + observation can replace complex algorithms Sometimes the easiest problems still sharpen thinking. 🚀 Momentum Status: Consistency intact. Small problems, clear logic, steady progress. On to Day 169. #DSA #Strings #LeetCode #ProblemSolving #CodingJourney #Java #ConsistencyWins
To view or add a comment, sign in
-
-
Day: 57/365 📌 LeetCode POTD: Special Positions in a Binary Matrix Easy Key takeaways/Learnings from this problem: 1. This one shows how precomputing row and column counts makes checking each cell super easy. 2. Instead of re-scanning the whole row and column every time, count once and reuse smartly. 3. Good reminder that brute force can often be optimized with a tiny bit of preprocessing. 4. Clean implementation and careful condition checking matter more than complex algorithms here. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
-
Solved a matrix problem : checking whether one matrix can be obtained from another using rotations. At first it looked a bit tricky, but the key idea was simple: 👉 A 90° rotation can be done using transpose + reverse each row This makes the solution clean and efficient (O(n²)) and is a useful pattern to remember for similar problems. #DataStructures #Algorithms #DSA #Java #LeetCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 37/75 — Letter Combinations of a Phone Number Today’s problem was about generating all possible letter combinations from a digit string (like a phone keypad). Approach: • Use backtracking (recursion) • Map each digit to its corresponding letters • Build combinations step by step • Explore all possible paths Key logic: for (char c : letters.toCharArray()) func(idx + 1, digits, temp + c, result, map); Time Complexity: O(4^n × n) Space Complexity: O(n) recursion stack Key Insight: Not every exponential problem is bad — here we must generate all combinations, so complexity is output-dependent. 37/75 🚀 #Day37 #DSA #Backtracking #Java #Algorithms #LeetCode
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