🚀 Day 48 / 100 | Combinations Intuition: The idea is to gradually build combinations by choosing numbers starting from a given index. By always moving forward, we avoid duplicates and ensure each combination is unique. Approach: Use backtracking to generate all possible combinations. Maintain a list to store the current combination. Start selecting numbers from a given starting point. Add a number to the list and recursively continue building the combination. Once the size of the list becomes k, we store it as a valid combination. After exploring a choice, remove the last number (backtrack) and try the next possible number. Complexity: Time Complexity: O(k*C(n,k)) Space Complexity: O(k) #100DaysOfCode #Java #DSA #LeetCode #Backtracking
Day 48: Backtracking Combinations in Java
More Relevant Posts
-
🚀 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 52 of #100DaysOfLeetCode 🚀 Solved Balanced Binary Tree (Easy) 🌳 Learned how to efficiently check if a binary tree is height-balanced using a single DFS traversal. Instead of recalculating heights multiple times (O(n²)), optimized it to O(n) by combining height calculation with balance checking. 💡 Key takeaway: Return -1 early when imbalance is detected to avoid unnecessary computations. #LeetCode #DSA #Java #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 58 of #100DaysOfCode Solved 165. Compare Version Numbers on LeetCode 🔗 🧠 Key Insight: Version strings are split by "." into multiple revisions. We compare each revision numerically (not lexicographically). Example: "1.01" = "1.1" (leading zeros don’t matter) ⚙️ Approach (Split + Compare): 1️⃣ Split both versions using "." 🔹 version1 → s1[] 🔹 version2 → s2[] 2️⃣ Traverse till max length of both arrays 3️⃣ For each index i: 🔹 num1 = i < s1.length ? parseInt(s1[i]) : 0 🔹 num2 = i < s2.length ? parseInt(s2[i]) : 0 4️⃣ Compare: 🔹 if num1 < num2 → return -1 🔹 if num1 > num2 → return 1 5️⃣ If all equal → return 0 ⏱️ Time Complexity: O(n + m) 📦 Space Complexity: O(n + m) (for split arrays) #100DaysOfCode #LeetCode #DSA #Strings #TwoPointers #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
🚀 𝗗𝗮𝘆 𝟭𝟬 𝗼𝗳 𝟭𝟬𝟬: 𝗦𝗼𝗹𝘃𝗶𝗻𝗴 LeetCode! Today I focused on applying the 𝗣𝗿𝗲𝗳𝗶𝘅 𝗦𝘂𝗺 concept to identify balanced positions in an array. 📌 𝗣𝗿𝗼𝗯𝗹𝗲𝗺𝘀 𝗦𝗼𝗹𝘃𝗲𝗱 𝗧𝗼𝗱𝗮𝘆 (𝗗𝗮𝘆 𝟭𝟬) 🔹 𝗙𝗶𝗻𝗱 𝘁𝗵𝗲 𝗠𝗶𝗱𝗱𝗹𝗲 𝗜𝗻𝗱𝗲𝘅 𝗶𝗻 𝗔𝗿𝗿𝗮𝘆 ✅ Goal: Find an index where the sum of elements on the left is equal to the sum on the right. If multiple exist, return the leftmost one. Approach: Calculated the total sum of the array, then traversed it while maintaining a running left sum. At each index, compared left sum with "(total sum - left sum - current element)" to check if it satisfies the condition, achieving O(n) time complexity. #100DaysOfCode #DSA #LeetCode #Java #ProblemSolving #CodingJourney #PrefixSum #Arrays
To view or add a comment, sign in
-
-
🚀 Day 78/100 – #100DaysOfCode Today, I solved “𝐒𝐞𝐭 𝐌𝐚𝐭𝐫𝐢𝐱 𝐙𝐞𝐫𝐨𝐞𝐬” problem on LeetCode 🔍 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐈𝐧𝐬𝐢𝐠𝐡𝐭: Given a matrix, if any element is 0, we need to set its 𝐞𝐧𝐭𝐢𝐫𝐞 𝐫𝐨𝐰 𝐚𝐧𝐝 𝐜𝐨𝐥𝐮𝐦𝐧 𝐭𝐨 0 — in-place without using extra space. 💡 𝐖𝐡𝐚𝐭 𝐈 𝐋𝐞𝐚𝐫𝐧𝐞𝐝: How to optimize space complexity to O(1) Using the first row & column as markers Importance of handling edge cases (first row & first column separately) ⚡ 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Check if 𝐟𝐢𝐫𝐬𝐭 𝐫𝐨𝐰/𝐜𝐨𝐥𝐮𝐦𝐧 𝐧𝐞𝐞𝐝𝐬 𝐭𝐨 𝐛𝐞 𝐳𝐞𝐫𝐨𝐞𝐝 Use first row & column to mark zeros Update the matrix accordingly Finally update first row & column if needed 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: Time: O(m × n) Space: O(1) #Day78 #100DaysOfCode #DSA #Java #LeetCode #CodingJourney #SoftwareDeveloper #KeepLearning
To view or add a comment, sign in
-
🚀 Day 55 of #100DaysOfCode Solved 147. Insertion Sort List on LeetCode 🔗 🧠 Key Insight: We apply the classic Insertion Sort, but on a linked list instead of an array. The challenge is handling pointer manipulation efficiently. ⚙️ Approach: 1️⃣ Create a dummy node to act as the start of the sorted list 2️⃣ Traverse the original list node by node 3️⃣ For each node: Find its correct position in the sorted part Insert it there by updating pointers 🔁 This builds a sorted list incrementally ⏱️ Time Complexity: O(n²) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #LinkedList #Sorting #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
🚀 LeetCode #61 – Rotate List Solved this problem by optimizing the rotation process instead of performing repeated shifts. Calculated the list length, reduced unnecessary rotations using k % length, and applied pointer manipulation to rotate the list efficiently. ✅ Time Complexity: O(n) ✅ Space Complexity: O(1) Another step forward in improving my understanding of Linked List operations. #LeetCode #DataStructures #Java #LinkedList #ProblemSolving
To view or add a comment, sign in
-
-
Day 15/100 – LeetCode Challenge Problem: Reverse Linked List Today’s problem focused on reversing a singly linked list using an iterative approach. Approach: Used three pointers to reverse the links: prev → keeps track of the previous node curr → current node being processed next → stores the next node before changing the link Steps: Store curr.next in next Reverse the link → curr.next = prev Move prev and curr one step forward Continue until the list ends. Finally, prev becomes the new head of the reversed list. Complexity: Time: O(n) Space: O(1) Concepts Practiced: Linked List pointer manipulation Iterative reversal technique In-place algorithm #100DaysOfCode #LeetCode #DSA #Java #LinkedList #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 25/100: Finding the "Gap" 🎯 Today's challenge: Search Insert Position. We all know Binary Search finds an element in O(log n), but what if the element isn't there? I learned that by the end of the search, the `left` pointer doesn't just give up—it points exactly to where that missing number *should* be inserted to keep the array sorted. It’s a powerful way to handle dynamic data without breaking the order. Quarter of the way through the challenge! 🚀 #100DaysOfCode #Java #DSA #BinarySearch #ProblemSolving #Unit3 #Day25 #LearnInPublic
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 87/100 – 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐂𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞 🚀 Problem: 228. 𝐒𝐮𝐦𝐦𝐚𝐫𝐲 𝐑𝐚𝐧𝐠𝐞𝐬 Today I solved a problem where we need to summarize consecutive numbers in a sorted unique array into ranges. 🔑 𝐈𝐝𝐞𝐚: Traverse the array and keep extending the range while consecutive numbers continue. Once the sequence breaks, close the range and store it. 💡 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Start with the first element as start Move forward while nums[i] + 1 == nums[i+1] If range exists → "start->end" Else → single number "start" 𝐊𝐞𝐲 𝐈𝐧𝐬𝐢𝐠𝐡𝐭: Efficient single pass solution (O(n)) by grouping consecutive elements on the fly. #LeetCode #Java #ProblemSolving #DSA #100DaysOfCode #CodingJourney
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