Solved LeetCode 17 – Letter Combinations of a Phone Number using backtracking in Java. Approach: Mapped each digit (2–9) to its corresponding characters using a simple array for O(1) access. Then used backtracking to build combinations digit by digit. For every digit: Pick each possible character Append → explore next digit → backtrack Key idea: Treat it like a tree of choices, where each level represents a digit and branches represent possible letters. Key learnings: Backtracking = build → explore → undo StringBuilder helps avoid unnecessary string creation Problems like this are about systematic exploration of choices Time Complexity: O(4^n * n) Space Complexity: O(n) recursion stack + output Consistent DSA practice is strengthening pattern recognition day by day. #Java #DSA #Backtracking #LeetCode #CodingInterview #SoftwareEngineering
Solved LeetCode 17 using Java Backtracking
More Relevant Posts
-
Leetcode Question Number 1848: Minimum Distance to the Target Element. I solved an interesting problem on finding the minimum distance in an array using Java!(Leetcode Daily Challenge) Given an array, a target value, and a starting index, the task is to find the minimum distance between the start index and any occurrence of the target element. Approach I used: 1.Traverse the array 2.Check for target element 3.Calculate distance using Math.abs(start - i) 4.Track minimum using Math.min() #Leetcode #DSA #Leetcode1848 #Java #Leetcodedailychallenge
To view or add a comment, sign in
-
-
Day 94 - LeetCode Journey Solved LeetCode 35: Search Insert Position in Java ✅ Classic Binary Search problem that tests your fundamentals. Instead of just finding the element, the twist is to return the correct insert position if it’s not present. The key idea is simple: keep narrowing the search space and finally return low, which represents the right position. Clean logic, high impact 💡 Key takeaways: • Strong grip on Binary Search fundamentals • Understanding search space boundaries • Returning correct insertion index • Writing efficient O(log n) solutions ✅ All test cases passed ⚡ O(log n) time and O(1) space Mastering basics like Binary Search is what builds real problem-solving strength 🔥 #LeetCode #DSA #Java #BinarySearch #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 23 of #75DaysOfCode Solved: Equal Row and Column Pairs 🔹 Problem: Given an n x n matrix, count the number of pairs (ri, cj) such that row ri and column cj are exactly the same. 🔹 Approach: • Stored all rows in a HashMap with their frequency • Converted each column into a comparable string format • Matched columns with stored rows to count equal pairs 🔹 Key Learning: Using StringBuilder instead of String concatenation significantly improves performance due to immutability of Strings in Java. 🔹 Time Complexity: O(n²) 🔹 Takeaway: Smart use of HashMap + efficient string handling can simplify and optimize matrix-based problems. #Day22 #75DaysOfCode #Java #DSA #LeetCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 66 of #100DaysOfLeetCode 💻✅ Solved #3427. Sum of Variable Length Subarrays problem in Java. Approach: • Iterated through each index of the array • Determined the starting index using i - nums[i] • Ensured the start index does not go below 0 • Calculated sum of elements from start to current index i • Added each subarray sum to the total Performance: ✓ Runtime: 1 ms (Beats 99.90% submissions) ✓ Memory: 45.22 MB (Beats 56.30% submissions) Key Learning: ✓ Practiced handling variable-length subarrays ✓ Improved understanding of index-based range calculations ✓ Strengthened nested loop logic for array problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #PrefixSum #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 82 of #100DaysOfLeetCode 💻✅ Solved #11. Container With Most Water problem in Java. Approach: • Used Two Pointer technique • Calculated area using min height and width • Moved pointer with smaller height inward • Tracked maximum area throughout Performance: ✓ Runtime: 5 ms (Beats 83.17% submissions) ✓ Memory: 77.35 MB (Beats 53.65% submissions) Key Learning: ✓ Mastered Two Pointer optimization technique ✓ Learned efficient area calculation strategy ✓ Improved decision-making for pointer movement Learning one problem every single day 🚀 #Java #LeetCode #DSA #TwoPointers #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 90 of #100DaysOfLeetCode 💻✅ Solved #42. Trapping Rain Water problem in Java. Approach: • Used Two Pointer technique • Maintained leftMax and rightMax boundaries • Calculated trapped water based on smaller side • Accumulated water while traversing Performance: ✓ Runtime: 0 ms (Beats 100.00% submissions) 🚀 ✓ Memory: 47.70 MB (Beats 72.36% submissions) Key Learning: ✓ Mastered Two Pointer approach for complex problems ✓ Learned optimal water trapping strategy ✓ Improved understanding of boundary-based calculations Learning one problem every single day 🚀 #Java #LeetCode #DSA #TwoPointers #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
📅 Day 10 – Strings in Java 📚 Topic: String Manipulation (Hashing) Today I solved the problem of checking whether two strings are anagrams using an efficient frequency-count approach. This helped me understand how hashing can be used to compare character distributions instead of sorting. ✔ Key Learnings: • Applied hashing using a frequency array • Improved understanding of character frequency comparison • Learned how to optimize from sorting (O(n log n)) to linear time (O(n)) Building problem-solving skills step by step and focusing on writing efficient code 🚀 #DSA #Strings #Java #ProblemSolving #LearningJourney
To view or add a comment, sign in
-
-
Day 93 - LeetCode Journey Solved LeetCode 9: Palindrome Number in Java ✅ At first glance, it feels like a string problem… but the real challenge is solving it without converting to string. Instead of reversing the whole number, I reversed only half of it and compared both parts. This avoids overflow and keeps it efficient. Smart approach > brute force 💡 Key takeaways: • Handling edge cases (negative numbers, trailing zeroes) • Reversing only half of the number • Avoiding extra space (no string conversion) • Writing optimized mathematical logic ✅ All test cases passed ⚡ O(log n) time and O(1) space Sometimes the best solutions are the simplest ones, just a different way of thinking 🔥 #LeetCode #DSA #Java #Math #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
Day 70 of #100DaysOfLeetCode 💻✅ Solved #3136. Valid Word problem in Java. Approach: • Checked if the word length is at least 3 • Traversed each character in the string • Ensured all characters are either letters or digits • Checked for presence of at least one vowel • Checked for presence of at least one consonant • Returned true only if all conditions are satisfied Performance: ✓ Runtime: 1 ms (Beats 99.62% submissions) 🚀 ✓ Memory: 43.08 MB (Beats 93.16% submissions) Key Learning: ✓ Practiced string validation with multiple conditions ✓ Learned efficient use of built-in character functions ✓ Strengthened logic building for edge case handling Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 68 of #100DaysOfLeetCode 💻✅ Solved #977. Squares of a Sorted Array problem in Java. Approach: • Traversed the array and squared each element • Used Arrays.sort() to sort the squared values • Returned the sorted array as the result Performance: ✓ Runtime: 10 ms (Beats 37.38% submissions) ✓ Memory: 47.98 MB (Beats 18.78% submissions) Key Learning: ✓ Practiced array transformation and sorting ✓ Learned how squaring affects order in sorted arrays ✓ Understood the importance of optimizing from O(n log n) to O(n) using two pointers Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #Sorting #ProblemSolving #CodingJourney #100DaysOfCode
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