Day 18 of #100DaysOfDSA (Java) Today I explored Divide and Conquer, a powerful problem-solving technique used in many efficient algorithms. Topics covered: 🔹 Merge Sort (stable, O(n log n)) 🔹 Quick Sort (efficient average case sorting) 🔹 Searching in a Sorted & Rotated Array 🔹 Understanding how problems can be broken into smaller subproblems and solved recursively Key takeaway: Divide and Conquer is not just about sorting — it’s about thinking recursively and optimizing solutions by reducing problem size. Also realized the importance of choosing the right algorithm: Merge Sort → stable and predictable Quick Sort → faster in practice but depends on pivot Day 18 From basic logic → to algorithmic thinking. #DSA #Java #DivideAndConquer #MergeSort #QuickSort #100DaysOfCode #ProblemSolving #DeveloperJourney
Java DSA: Divide and Conquer Techniques
More Relevant Posts
-
Day 66 — LeetCode Progress (Java) Problem: Find the Difference of Two Arrays Required: Given two integer arrays, return: Elements present in nums1 but not in nums2 Elements present in nums2 but not in nums1 Idea: Use sets to remove duplicates and quickly check membership. Approach: Convert both arrays into sets Iterate over nums1 set: Add elements not present in nums2 set to result1 Iterate over nums2 set: Add elements not present in nums1 set to result2 Return both lists Time Complexity: O(n + m) Space Complexity: O(n + m) #LeetCode #DSA #Java #HashSet #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 60 — LeetCode Progress (Java) Problem: Count Bad Pairs Required: Given an array nums, count the number of bad pairs (i, j) such that: j - i ≠ nums[j] - nums[i] Idea: Transform the condition to group good pairs using: nums[i] - i Pairs with the same value of (nums[i] - i) are good pairs. Total pairs − good pairs = bad pairs. Approach: Use a HashMap to store frequency of (nums[i] - i). Traverse the array: For each index, compute key = nums[i] - i Count how many times this key has appeared before → contributes to good pairs Update the frequency in the map Keep track of: Total possible pairs Good pairs Return: bad pairs = total pairs - good pairs Time Complexity: O(n) Space Complexity: O(n) #LeetCode #DSA #Java #HashMap #Arrays #Algorithms #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 33 of #GFG60 — Staying Consistent Today’s problem: Length of Longest Cycle in a Graph 🔍 Key Concepts: • Graph traversal • Cycle detection using HashMap • Tracking visit order to compute cycle length • Efficient O(V) approach 💡 Learned how to detect cycles and calculate their length without redundant traversals. Consistency is starting to compound 📈 33 days in — no breaks. #GeeksforGeeks #DSA #CodingJourney #Java #GraphTheory #Consistency #KeepGrinding
To view or add a comment, sign in
-
-
🚀 Day 6 of #100DaysOfCode | Pattern: Two Pointers Today I tackled a classic Linked List problem: 👉 Remove Nth Node From End of List At first, I thought of a brute force approach: Traverse the list to find length Then remove (length - n) node ❌ Works, but requires 2 passes 💡 Then I learned the optimal approach (Two Pointers): Use fast and slow pointers Move fast n steps ahead Move both together until fast reaches end Delete the node using slow ✅ Only 1 pass ✅ Cleaner and efficient ⚠️ Mistakes I made (important learning): Forgot to use a dummy node → failed for head deletion Got confused between moving n vs n+1 steps Faced null pointer issues in edge cases 🔥 Key Takeaway: Two pointer technique is not just for arrays, it’s super powerful in Linked Lists too 📈 Progress Update: Consistency building day by day Next week: Starting a new pattern Along with revision of Two Pointers #100DaysOfCode #DSA #Java #LinkedList #CodingJourney #ProblemSolving #LearnInPublic #PatternWise
To view or add a comment, sign in
-
-
🚀 Day 21 of #128DaysOfCode 🔍 Key Learnings: Efficient searching in O(log n) Using low & high to narrow the range Finding correct position even if target is absent 🧠 Approach: Compare mid with target → move left/right → return index or insert position Consistency is key 🔥 #DSA #Java #CodingJourney #PlacementPreparation
To view or add a comment, sign in
-
-
Day 70 - Next Greater Node Understanding how to find the next larger value for each node using stack optimization. Approach: • Convert linked list → array for easy indexing • Use a stack to track indices • Compare current value with stack top • Update results when a greater value is found Key Insight: Monotonic stack helps avoid unnecessary comparisons Time Complexity: O(n) Space Complexity: O(n) #Day70 #LeetCode #Java #CodingPractice #TechJourney #DSA #LinkedList
To view or add a comment, sign in
-
-
🚀 Day 32 of #100DaysOfDSA (Java) Today was more about practice and strengthening concepts rather than learning new topics. I attended a live session with my mentor where I: 🔹 Solved multiple Binary Search Tree (BST) problems 🔹 Worked through assignment questions 🔹 Improved my problem-solving approach with guided feedback Key takeaway: Solving problems with guidance helped me understand where I make mistakes and how to think more efficiently. Real learning happens when you struggle, solve, and refine your approach — not just when you learn new concepts. Day 32 ✅ Focused on consistency, practice, and improving problem-solving skills. #DSA #Java #BST #ProblemSolving #100DaysOfCode #DeveloperJourney #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day 35 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Valid Anagram Problem Insight: Given two strings, check if one is an anagram of the other. Approach: • First, check if the strings have the same length; if not, return false • Convert both strings to character arrays • Sort both arrays • Compare the sorted arrays — if equal, the strings are anagrams Time Complexity: • O(n log n) — due to sorting the arrays Space Complexity: • O(n) — for the character arrays Key Learnings: • Sorting is a simple and effective way to compare character compositions • Edge cases like different lengths should be handled first • Breaking the problem into small steps makes it easy to reason about Takeaway: Sometimes, sorting can reduce a seemingly complex problem into a simple comparison. #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #Strings
To view or add a comment, sign in
-
-
🚀 Day 84/100 – 𝐒𝐞𝐚𝐫𝐜𝐡 𝐢𝐧 𝐑𝐨𝐭𝐚𝐭𝐞𝐝 𝐒𝐨𝐫𝐭𝐞𝐝 𝐀𝐫𝐫𝐚𝐲 𝐈𝐈 🔍 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠: Binary search works great on sorted arrays, but duplicates introduce ambiguity — making it harder to decide which half is sorted. 💡 𝐂𝐨𝐫𝐞 𝐈𝐝𝐞𝐚: Use modified binary search Identify the sorted half Handle duplicates by shrinking the search space ⚡ 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Find 𝐦𝐢𝐝 If 𝐭𝐚𝐫𝐠𝐞𝐭 𝐟𝐨𝐮𝐧𝐝 → 𝐫𝐞𝐭𝐮𝐫𝐧 𝐭𝐫𝐮𝐞 𝐇𝐚𝐧𝐝𝐥𝐞 𝐝𝐮𝐩𝐥𝐢𝐜𝐚𝐭𝐞𝐬 (𝐥𝐨𝐰++) Check which half is sorted Narrow down search accordingly #Day84 #100DaysOfCode #Java #DSA #LeetCode #BinarySearch #CodingJourney
To view or add a comment, sign in
-
-
🧠 Day 30 / 100 – DSA Practice Solved Remove Duplicates from Sorted List on LeetCode 🔗✅ 🔹 Problem Insight: Given a sorted linked list, remove duplicates so each element appears only once. 🔹 Approach: Used a single pointer traversal: Compared current node with next node Skipped duplicate nodes by updating links Leveraged the fact that the list is already sorted 🔹 Complexity: Time → O(n) Space → O(1) 💯 Result: ✔️ All test cases passed ⚡ Runtime: 0 ms (Beats 100%) Consistency builds confidence 💪🚀 #Day30 #100DaysOfCode #LeetCode #Java #DSA #LinkedList #CodingJourney #ProblemSolving
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