Day 74/100: LeetCode Challenge - Letter Combinations of a Phone Number 📱 Today I solved the classic backtracking problem - generating all possible letter combinations from a phone number! Problem: Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent (just like the old phone keypads). Example: Input: "23" → Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] My approach: Used backtracking to explore all possible combinations Mapped each digit to its corresponding letters (2→abc, 3→def, etc.) Built combinations recursively by trying each letter for the current digit Results: ✅ Runtime: 3 ms (beats 32.71%) ✅ Memory: 48.65 MB (beats 26.99%) Key takeaway: Backtracking is a powerful technique for generating all combinations/permutations. The key is to build the solution incrementally and backtrack when we've explored a complete path. This problem is a perfect example of when recursion shines! #100DaysOfCode #LeetCode #Java #Backtracking #CodingChallenge #ProblemSolving #Day73 #Programming
LeetCode Challenge: Letter Combinations of a Phone Number
More Relevant Posts
-
Day 75/100: LeetCode Challenge - Count and Say 🔢 Today I tackled the "Count and Say" sequence problem - a fascinating exercise in string manipulation and pattern recognition! Problem: The count-and-say sequence starts with "1". Each subsequent term is generated by "saying" the previous term - counting consecutive digits and saying the count followed by the digit. Example: 1 → "one 1" → "11" 11 → "two 1s" → "21" 21 → "one 2, one 1" → "1211" My approach: Started with base case "1" Iteratively built each next term by traversing the current string Counted consecutive identical characters and appended count + digit to StringBuilder Used StringBuilder for efficient string concatenation Results: ✅ Runtime: 3 ms (beats 72.74%) ✅ Memory: 42.90 MB (beats 84.80%) Key takeaway: Sometimes the most straightforward iterative approach is the best! This problem teaches the importance of careful string traversal and StringBuilder usage for optimal performance. The key was recognizing the pattern: each new string is just a "run-length encoding" of the previous one. #100DaysOfCode #LeetCode #Java #StringManipulation #CodingChallenge #ProblemSolving #Day74 #Programming
To view or add a comment, sign in
-
-
🔥 𝗗𝗮𝘆 𝟴𝟭/𝟭𝟬𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 𝟳𝟴. 𝗦𝘂𝗯𝘀𝗲𝘁𝘀 | 𝗠𝗲𝗱𝗶𝘂𝗺 | 𝗝𝗮𝘃𝗮 Given an integer array, return all possible subsets (the power set) — no duplicates allowed. 𝗠𝘆 𝗮𝗽𝗽𝗿𝗼𝗮𝗰𝗵 — 𝗕𝗮𝗰𝗸𝘁𝗿𝗮𝗰𝗸𝗶𝗻𝗴: ✅ At each index, make a choice: include or exclude ✅ Recurse with the element added → then backtrack (remove it) ✅ Recurse again without the element ✅ Base case: when index == nums.length, save the current subset This explores every branch of the decision tree, giving us all 2ⁿ subsets cleanly. 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆: ⏱ Time: O(n × 2ⁿ) — 2ⁿ subsets, each copied in O(n) 📦 Space: O(n) recursion depth Backtracking is one of those patterns that feels magical once it clicks — the "add → recurse → remove" rhythm is the heart of so many classic problems. 📂 𝗙𝘂𝗹𝗹 𝘀𝗼𝗹𝘂𝘁𝗶𝗼𝗻 𝗼𝗻 𝗚𝗶𝘁𝗛𝘂𝗯: https://lnkd.in/gZmezt_g 19 more days to go. Almost there! 💪 #LeetCode #Day81of100 #100DaysOfCode #Java #DSA #Backtracking #Recursion #CodingChallenge #Programming
To view or add a comment, sign in
-
🔥 𝗗𝗮𝘆 𝟴𝟬/𝟭𝟬𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 𝟭𝟱𝟳𝟮. 𝗠𝗮𝘁𝗿𝗶𝘅 𝗗𝗶𝗮𝗴𝗼𝗻𝗮𝗹 𝗦𝘂𝗺 | 𝗘𝗮𝘀𝘆 | 𝗝𝗮𝘃𝗮 Given an n×n matrix, return the sum of both diagonals without double-counting the centre on odd-sized grids. 𝗠𝘆 𝗮𝗽𝗽𝗿𝗼𝗮𝗰𝗵: ✅ Single loop — O(n) time, O(1) space ✅ Add both mat[i][i] and mat[n-i-1][i] per iteration ✅ Subtract mat[n/2][n/2] once if n is odd No extra arrays. No second pass. Just clean linear logic. The beauty of this one is that both diagonals can be walked in the same loop — and the edge case resolves with a single parity check. Sometimes the simplest solution is the best solution. 💡 📂 𝗙𝘂𝗹𝗹 𝘀𝗼𝗹𝘂𝘁𝗶𝗼𝗻 𝗼𝗻 𝗚𝗶𝘁𝗛𝘂𝗯: https://lnkd.in/gcWbQbbA 20 more days to go. Let's finish strong! 💪 #LeetCode #Day80of100 #100DaysOfCode #Java #DSA #CodingChallenge #ProblemSolving #Programming
To view or add a comment, sign in
-
Stop using ArrayList for everything. Picking the right data structure isn't just about making your code work; it's about making it perform. Choosing a Set over a List can be the difference between an O(n) and an O(1) lookup. This infographic is one of the best visual breakdowns I’ve seen for the Java Collections Framework: List: When order and duplicates matter. Set: When uniqueness is your top priority. Queue: For that "first-in, first-out" processing flow. Map: When you need fast retrieval via key-value pairs. Which one do you find yourself reaching for most often in your day-to-day? #Java #Programming #SoftwareEngineering #JavaCollections #CodingTips
To view or add a comment, sign in
-
-
🚀 Daily DSA Practice – Day 62 | Dynamic Programming – Coin Change II (Java) Continuing my Dynamic Programming journey, today I solved a problem focused on counting combinations instead of minimizing values. 📌 Problem Solved (LeetCode): 518. Coin Change II (Medium) 🎯 Concept: Unbounded Knapsack (Count of Ways) 🧠 Problem Idea: Given an amount and coin denominations, find the number of combinations that make up that amount. Unlike Coin Change I, where we minimize coins, here we count total ways. DP Relation dp[j] = dp[j] + dp[j - coin] 🔍 What I Practiced: ✔ Difference between Minimization DP vs Counting DP ✔ Applying Unbounded Knapsack pattern ✔ Using 1D DP optimization ✔ Understanding order-independent combinations This problem helped me clearly understand how DP problems can change significantly based on whether we count ways or optimize values. #DSA #LeetCode #DynamicProgramming #Java #Knapsack #ProblemSolving #InterviewPreparation #Consistency
To view or add a comment, sign in
-
LeetCode Problem || Find All Possible Stable Binary Arrays II (3130)🚀 🔹 Problem Idea: We are given a number of 0s and 1s and a constraint called limit. The goal is to count the number of possible binary arrays such that no more than limit consecutive identical elements appear. 🔹 Approach: I used Dynamic Programming to track the number of valid arrays formed with: i zeros j ones and the last placed element (0 or 1). The DP state helps ensure that the consecutive limit condition is maintained while building the array. Always enjoying the process of learning and improving problem-solving skills! 💡 #LeetCode #DynamicProgramming #ProblemSolving #Java #CodingPractice #SoftwareEngineering
To view or add a comment, sign in
-
-
Solved LeetCode 1009 – Complement of Base 10 Integer today. In simple terms, the problem asks us to flip every bit of a number’s binary representation — change all 0s to 1s and all 1s to 0s — and then convert it back to a decimal number. The key idea was to create a bit mask of all 1s with the same length as the number’s binary form, and then use the XOR (^) operation to flip the bits. A small problem, but a good reminder of how powerful bit manipulation can be in programming. #LeetCode #DSA #Java #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 11/100 Day Coding Challenge Today, I solved the LeetCode problem: Container With Most Water using Java. Here’s a detailed breakdown of my approach and learning: Problem Statement: Given an array of non-negative integers representing heights of vertical lines on a coordinate plane, find two lines that, along with the x-axis, form a container that holds the maximum water. Challenges: A brute-force approach would check all possible pairs of lines (O(n²)), which is inefficient for large arrays. I aimed for an optimized solution using the two-pointer technique. Approach (Two-Pointer Technique): Initialize two pointers: l at the start, r at the end of the array. Compute the current area: curWater = (r - l) * min(height[l], height[r]). Update maximum area found so far. Move the pointer pointing to the shorter line inward: If height[l] < height[r], increment l. Else, decrement r. Repeat until the pointers meet. #100DaysOfCode #Java #LeetCode #TwoPointerTechnique #ProblemSolving #Algorithms #SoftwareEngineering #Day11
To view or add a comment, sign in
-
-
Today I implemented Array Reversal in Java using the Two-Pointer Technique! 🔄 Logic: ∙ Set left = 0 and right = arr.length - 1 ∙ Swap elements at both ends ∙ Move pointers inward until they meet ✅ Input: {1, 2, 3, 4, 5} ✅ Output: 5 4 3 2 1 💡 Why Two-Pointer? Instead of using extra space, we swap in-place — making it O(n) time and O(1) space! No extra array needed. Just two pointers doing the work. 💪 Every small concept I practice brings me one step closer to DSA mastery. Keep building. Keep learning. 🙌 #100daysofcode #dsa #java #program #array #problem #leetcode #javadeveloper #learning
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