📅 Day 41 of #100DaysOfCode Problem: Merge k Sorted Lists (LeetCode 23) This one was all about optimization and clean recursion. Instead of merging lists one by one, I used a divide and conquer approach merge them in pairs, just like merge sort. Approach: 1️⃣ If there’s only one list, return it - base case. 2️⃣ Split the range of lists into two halves using recursion. 3️⃣ Merge both halves using a helper function that merges two sorted lists. 4️⃣ Keep dividing until everything is combined into one sorted list. #100DaysOfCode #LeetCode #DSA #Cplusplus #ProblemSolving #DivideAndConquer #Recursion #CodingChallenge #Algorithms #Programming #CodeNewbie #DeveloperLife #LearningInPublic #KeepLearning #SoftwareEngineering #TechCommunity #DailyDSA #GrowthMindset #Motivation
Harsh Srivastava’s Post
More Relevant Posts
-
📅 Day 28 of #100DaysOfCode 🚀 Problem: 49. Group Anagrams (LeetCode) Approach: -> For each string, sort its characters — the sorted version acts as a unique key for its anagram group. -> Store all words with the same sorted key inside a hash map (unordered_map<string, vector<string>>). -> After processing all words, collect all grouped values from the map into a result vector. ->This leverages hashing + sorting for efficient grouping — O(n * k log k) where k is average string length. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Cplusplus #CodingChallenge #Algorithms #DataStructures #Hashing #StringManipulation #CodingCommunity #Programming #DeveloperLife #LearnToCode #TechCommunity #DailyDSA #CodeNewbie #SoftwareEngineering #CodingJourney #Consistency #KeepLearning #LearningInPublic #GrowthMindset #Motivation
To view or add a comment, sign in
-
-
📅 Day 47 of #100DaysOfCode Problem: Combination Sum II (LeetCode 40) Approach: 1️⃣ Sorted the array to handle duplicates easily. 2️⃣ Used recursion to explore each number — either include it or skip it. 3️⃣ Reduced the target as I added elements, and when the target hit 0, that path became a valid combination. 4️⃣ Skipped duplicates using a simple check: if (i > idx && candidates[i] == candidates[i-1]) continue. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Backtracking #Recursion #Cplusplus #CodingChallenge #Algorithms #Programming #DeveloperLife #CodeNewbie #SoftwareEngineering #DailyDSA #CodingJourney #KeepLearning #TechCommunity #Motivation #GrowthMindset
To view or add a comment, sign in
-
-
📅 Day 35 of #100DaysOfCode Problem: Search in Rotated Sorted Array II (LeetCode 81) Approach: 1️⃣ First, handled duplicates by skipping consecutive equal elements from both ends to avoid confusion while finding the rotation point. 2️⃣ Used a modified binary search to find the pivot (the smallest element’s index) — this separates the rotated parts of the array. 3️⃣ Performed binary search on both halves — before and after the pivot — to check where the target lies. 4️⃣ Returned true if found in either part, else false. #100DaysOfCode #LeetCode #BinarySearch #RotatedArray #ProblemSolving #Algorithms #DSA #Cplusplus #CodingChallenge #Programming #DeveloperLife #CodeNewbie #DailyDSA #TechCommunity #KeepLearning #SoftwareEngineering #LearningInPublic #Motivation
To view or add a comment, sign in
-
-
📅 Day 46 of #100DaysOfCode Problem: Combinations (LeetCode 77) Approach: 1️⃣ Used recursion to build combinations incrementally. 2️⃣ For every number, we have two choices — include it or skip it. 3️⃣ Once we’ve picked k numbers, added that combination to the result. 4️⃣ Used backtracking (pop_back) to explore the next possibility cleanly. #100DaysOfCode #LeetCode #DSA #Backtracking #Recursion #ProblemSolving #Cplusplus #CodingChallenge #Algorithms #Programming #DeveloperLife #CodeNewbie #SoftwareEngineering #CodingJourney #DailyDSA #KeepLearning #GrowthMindset #Motivation #TechCommunity
To view or add a comment, sign in
-
-
📅 Day 42 of #100DaysOfCode Problem: Subsets (LeetCode 78) Approach: 1️⃣ Used backtracking to explore every possibility — either include the current element or skip it. 2️⃣ When the index reaches the end, added the current subset to the result. 3️⃣ Backtracked properly to remove elements before exploring the next choice. 4️⃣ This ensures every possible combination is covered without duplicates. #100DaysOfCode #LeetCode #Backtracking #Recursion #DSA #Cplusplus #ProblemSolving #CodingChallenge #Algorithms #Programming #DeveloperLife #CodeNewbie #DailyDSA #TechCommunity #KeepLearning #GrowthMindset #SoftwareEngineering #LearningInPublic #Motivation
To view or add a comment, sign in
-
-
📅 Day 48 of #100DaysOfCode Problem: Search in Rotated Sorted Array II (LeetCode 81) Approach: 1️⃣ First, used a pivot function to find the smallest element’s index, skipping duplicate values on both sides. 2️⃣ Once the pivot was found, split the array into two sorted parts. 3️⃣ Applied normal binary search on both halves to find the target. 4️⃣ Combined both steps to handle rotations and duplicates efficiently. #100DaysOfCode #LeetCode #DSA #ProblemSolving #BinarySearch #Cplusplus #CodingChallenge #Algorithms #Programming #DeveloperLife #CodeNewbie #SoftwareEngineering #CodingJourney #DailyDSA #KeepLearning #TechCommunity #GrowthMindset #Motivation
To view or add a comment, sign in
-
-
📅 Day 31 of #100DaysOfCode Problem: Reverse Pairs (LeetCode 493) Approach: 1️⃣ Divide the array using merge sort to count pairs efficiently. 2️⃣ Count cross-pairs where nums[i] > 2 * nums[j] while merging. 3️⃣ Merge the halves back in sorted order to maintain correct comparisons. 4️⃣ Sum up counts from left, right, and cross halves for the final result. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Cplusplus #CodingChallenge #Algorithms #Programming #DeveloperLife #CodeNewbie #DailyDSA #SoftwareEngineering #CodingJourney #LearningInPublic #TechCommunity #KeepLearning #DivideAndConquer #GrowthMindset #Motivation
To view or add a comment, sign in
-
-
📅 Day 36 of #100DaysOfCode Today’s challenge was one of the most interesting and tricky recursion problems! Problem: Regular Expression Matching (LeetCode #10) 🔍 Approach: The goal is to determine if a given string text matches a pattern that includes: . → Matches any single character * → Matches zero or more occurrences of the preceding element 1️⃣ Used recursion to check character-by-character matches. 2️⃣ For each step: Checked if the current characters match (text[0] == pattern[0] or pattern[0] == '.'). If the next pattern character is *, explored two possibilities: Skip * and the previous character (zero occurrence). Use * to match one or more occurrences (consume one character from text). 3️⃣ Continued recursively until the entire text and pattern were checked. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Cplusplus #CodingChallenge #Algorithms #Programming #DeveloperLife #CodeNewbie #DailyDSA #SoftwareEngineering #CodingJourney #LearningInPublic #TechCommunity #KeepLearning #Recursion #GrowthMindset #Motivation
To view or add a comment, sign in
-
-
📅 Day 50 of #100DaysOfCode Problem: Simplify Path (LeetCode 71) Approach: 1️⃣ Used a stringstream to split the path by '/'. 2️⃣ Ignored empty tokens and "." since they don’t change the directory. 3️⃣ For "..", popped the last directory from the stack (if any). 4️⃣ Rebuilt the canonical path from the stack in the correct order. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Stacks #Cplusplus #CodingChallenge #Algorithms #Programming #DeveloperLife #CodingJourney #CodeNewbie #DailyDSA #SoftwareEngineering #KeepLearning #GrowthMindset #Motivation #TechCommunity #CleanCode
To view or add a comment, sign in
-
-
📅 Day 33 of #100DaysOfCode Problem: Basic Calculator (LeetCode 224) Approach: 1️⃣ Parsed the string character by character, keeping track of current number, sign, and result. 2️⃣ When encountering '+' or '-', added the previous number to the result and reset the current number. 3️⃣ Used a stack to handle parentheses — pushed the current result and sign when '(' was found, then restored them after ')'. 4️⃣ Carefully computed the final result by adding the last pending number after traversal. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Stack #Cplusplus #CodingChallenge #Algorithms #Math #CodeNewbie #Programming #SoftwareEngineering #CodingJourney #TechCommunity #DeveloperLife #KeepLearning #LearningInPublic #Motivation
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