Day 67 of #100DaysOfCode Today I solved the classic Permutations problem using Backtracking (Swap Method). At first glance, it feels like we just need to “rearrange” numbers — but the real learning is understanding how recursion explores every possible arrangement systematically. 🔁 The key idea: Fix one position → try every element → recurse for the next position → backtrack. This pattern (choose → explore → undo) is the backbone of many advanced problems like: Subsets Combinations N-Queens Sudoku Solver 📌 Time Complexity: O(n!) 📌 Space Complexity: O(n) (excluding result storage) The biggest takeaway? Backtracking is not about memorizing code — it’s about mastering the decision tree in your mind. One more step forward. 🚀 #100DaysOfCode #DSA #Backtracking #Java #ProblemSolving #dsawithkunal
Permutations solved with Backtracking in Java
More Relevant Posts
-
🚀 Day 20/60 Completed – LeetCode Problem of the Day Challenge Today’s challenge: Check if Binary String Has at Most One Segment of Ones The problem asks us to determine whether a binary string contains at most one continuous segment of '1's. 🧠 Approach & Key Learnings: • Traversed the string once from left to right. • Once a segment of '1's starts, we track it. • If we encounter '0' after the first segment of '1's, we mark that a break occurred. • If another '1' appears after that zero, it means there is more than one segment of ones → return false. • Otherwise, the string contains only one contiguous segment of ones → return true. ⚙️ Key Concepts Practiced: • String traversal • Segment detection in binary strings • Boolean flag tracking • Writing clean linear-time logic Small problem, but a good exercise in carefully tracking patterns while scanning a string. 20 days down. Consistency is getting stronger every day. ⚡ 40 days to go — staying locked in. 🔥 #LeetCode #60DaysChallenge #ProblemOfTheDay #DSA #Java #CodingJourney #Consistency #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 50 of #365DaysOfCode – LeetCode Practice Github link: https://lnkd.in/gGUy_MKZ Today I solved the problem “Count Binary Substrings.” The challenge was to count the number of non-empty substrings in a binary string that contain an equal number of 0s and 1s, with all identical digits grouped consecutively. Instead of checking all possible substrings (which would be inefficient), I learned an important pattern: 🔹 Valid substrings are formed between consecutive groups of 0s and 1s. 🔹 The number of valid substrings between two groups is determined by 👉 min(size of previous group, size of current group) This approach helped reduce the time complexity to O(n) with O(1) space. 💡 Key Takeaway: Sometimes the optimal solution comes from observing patterns in grouping rather than brute-force substring checking. Consistency in problem-solving is sharpening my understanding of patterns and optimization every day 📈 #Java #DSA #LeetCode #ProblemSolving #CodingJourney #BitManipulation
To view or add a comment, sign in
-
-
Day 12 – Binary Tree Preorder Traversal 🚀 Continuing my DSA journey with Striver’s A2Z Sheet / LeetCode practice. Today’s problem was about tree traversal, specifically Preorder Traversal, which is one of the most fundamental concepts in Binary Trees. Approach :- Preorder traversal follows: 1️⃣ Visit the root node 2️⃣ Traverse the left subtree 3️⃣ Traverse the right subtree Time Complexity : O(N) Space Complexity : O(N) GitHub Code :- https://lnkd.in/e7skAAvF #LeetCode #DSA #StriverA2Z #CodingJourney #Java #BinaryTree #TreeTraversal #ProblemSolving #CodingPractice #SoftwareEngineering #TechInterviewPrep #Day12#DeveloperJourney
To view or add a comment, sign in
-
-
🚀Day 11 of #Leetcode75 LeetCode #392 – Is Subsequence | Two Pointer Approach Today I solved “Is Subsequence” (Easy) and revised an important concept — the Two Pointer Technique. 🔎 Problem Summary: Given two strings s and t, determine whether s is a subsequence of t. A subsequence maintains the relative order of characters but doesn’t need to be continuous. 💡 Key Insight: Instead of using extra space or complex logic, we can solve this efficiently using two pointers: ✔ One pointer for s ✔ One pointer for t ✔ Move forward and match characters in order ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) This problem reinforces how powerful simple logic can be when applied correctly. Consistency > Complexity 💪 Excited to keep improving step by step! #LeetCode #DSA #Java #CodingPractice #ProblemSolving #100DaysOfCode #TechJourney
To view or add a comment, sign in
-
-
Day 33 of Practicing DSA on LeetCode Solved: • (21) Merge Two Sorted Lists – Easy Focused on: • Merging two sorted linked lists efficiently • Using a dummy node to simplify pointer handling • Comparing nodes and rewiring links in-place • Avoiding extra space while maintaining order This problem looks simple, but it builds the foundation for many advanced linked list patterns. Small problems → strong fundamentals. Consistency over everything. #DSA #Java #LeetCode #LinkedList #ProblemSolving #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
Day 8 Today I solved “Check if Binary String Has at Most One Segment of Ones” on LeetCode. At first glance, the problem looks simple: Given a binary string, check whether it contains only one continuous segment of '1's. Example: "110" → Valid (one segment of 1s) "1001" → Invalid (two separate segments of 1s) While solving it, I realized an interesting observation: 👉 If a binary string has more than one segment of 1s, the pattern "01" must appear before another "1". So instead of counting segments explicitly, we can simply check whether '01' appears and is followed by another '1'. This turns the problem into a very efficient linear scan with O(n) time complexity. 💡 Key takeaway: Sometimes the simplest solution comes from recognizing patterns in the string rather than simulating the whole process. Also happy to see my solution running at 0 ms runtime (100% faster) 🚀 #LeetCode #DSA #ProblemSolving #Java #CodingJourney #BinaryStrings
To view or add a comment, sign in
-
-
🚀 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
To view or add a comment, sign in
-
-
🚀 Day 74 of #100DaysOfCode Today I solved Search in Rotated Sorted Array from LeetCode using a modified Binary Search approach. 🧠 Problem Insight: Even though the array is rotated, one half is always sorted. By identifying the sorted half, we can decide where to move — left or right. ⚡ Key Learning: Instead of thinking “array is rotated ”, Think → “One side is still sorted ” 💻 Approach: Use Binary Search Check which half is sorted Verify if target lies in that half Reduce search space accordingly ⏱ Complexity: Time: O(log n) Space: O(1) #Day74 #100DaysOfCode #DSA #BinarySearch #Java #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 27 of My LeetCode Journey 📌 Problem: Maximum Product of Three Numbers (LeetCode 628) Today’s challenge was to find the maximum product of any three numbers in an integer array. The important observation is that the maximum product can come from: • The three largest numbers, or • The two smallest numbers (negative values) multiplied by the largest number. 🧠 Approach Used: Single Pass (Tracking Maximum & Minimum Values) Instead of sorting the array, we iterate through the array once and keep track of: The three largest numbers The two smallest numbers Finally, we compute the maximum between: 1️⃣ max1 × max2 × max3 2️⃣ min1 × min2 × max1 ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) This approach avoids sorting and efficiently finds the result in a single traversal of the array. #Day27 #LeetCode #DSA #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 27/100 – LeetCode Challenge 🚀 Problem: Sort List Approach: Applied Merge Sort on the linked list Used slow and fast pointers to find the middle Recursively sorted both halves Merged the sorted halves Time Complexity: O(n log n) Space Complexity: O(log n) (recursion stack) Key takeaway: Merge sort is the most efficient sorting technique for linked lists, as it avoids random-access operations required by other algorithms. #LeetCode #100DaysOfCode #DSA #Java #LinkedList #MergeSort #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
is this next permutation problem