#200DaysOfCode – Day 109 Problem: LeetCode 17 – Letter Combinations of a Phone Number Task:- Given a string of digits (2–9), return all possible letter combinations based on the phone keypad mapping. Example: Input: digits = "23" Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] My Approach: Used a mapping array to store digit-to-letter relationships. Applied backtracking to build combinations character by character. Once the current combination length matched the input length, added it to the result list. Used StringBuilder for efficient string manipulation. Time Complexity: O(4ⁿ) Space Complexity: O(n) (recursive stack) Backtracking is a powerful technique when dealing with combinations and permutations. Breaking the problem into smaller recursive steps makes complex logic much easier to handle. #takeUforward #200DaysOfCode #LeetCode #Java #Backtracking #Recursion #ProblemSolving #DSA #CodeNewbie #Consistency #LearnEveryDay
LeetCode 17 - Letter Combinations of a Phone Number
More Relevant Posts
-
🚀 Day 70 of #100DaysOfLeetCode Problem: 4Sum Difficulty: Medium Key Concept Learned: Sorting + Two Pointers + Duplicate Handling Today’s challenge was about finding all unique quadruplets in an array whose sum equals a given target. The optimized approach involved sorting the array, fixing two indices, and then using the two-pointer technique to efficiently search for valid combinations. Key takeaways: Sorting enables efficient pointer movement and duplicate detection Skipping duplicates at every level (i, j, left, right) is crucial to ensure uniqueness Two-pointer technique reduces the brute force complexity significantly Careful pointer handling avoids repeated results and improves performance A great problem for strengthening array manipulation, pointer logic, and edge-case handling. On to Day 71! 💪🔥 #LeetCode #DSA #Java #TwoPointers #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
📅 Day 107 of #160DaysOfDSA 🔐 Decode the String ✅ Today’s problem helped me understand how stacks simplify decoding nested string patterns in an clean and structured way. 🧠 Problem in Short Given an encoded string of the form: k[encoded_string] ▪️ The substring inside [] must be repeated k times ▪️ Nested encodings are allowed 🔹 Example: Input: 3[b2[ca]] Output: bcacabcacabcaca 🚀 Core Idea We decode the string by traversing it character by character and using two stacks: 🔸 Count Stack → stores repetition numbers 🔸 String Stack → stores previous partial strings 🔁 Execution Flow ✔️ If digit → build the number ✔️ If [ → save current state (number + string) ✔️ If ] → • repeat current string • attach it to the previous string ✔️ If alphabet → append to the current string ⏱️ Complexity Time: O(n × k) Space: O(n) #DSA #Stack #DecodeString #GeeksForGeeks #ProblemSolving #Java #CodingJourney #GFG #Day107 #StringBuilder
To view or add a comment, sign in
-
-
Solved LeetCode 4 – Median of Two Sorted Arrays ✅ Yeah, I know. This is a Hard problem and the expected solution is O(log(min(n, m))) using binary search and partitioning. But today, I went with clarity first. I combined both arrays, sorted them, and directly computed the median. 📌 Result? ✔️ All test cases passed ✔️ Correct output ✔️ Clear logic Is it the optimal solution? ❌ Is it a valid one? ✅ And that’s the point. Sometimes the real learning is: Understanding why a brute-force solution works Then understanding why it’s not optimal And only then moving to the complex solution Hard problems aren’t solved in one jump. They’re solved in iterations. Binary search partitioning is next. But today, correctness comes first. #LeetCode #DSA #ProblemSolving #Java #CodingJourney #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
LeetCode Practice - 944. Delete Columns to Make Sorted 🧠 Problem Idea ✅ You are given n strings, all of the same length. ✅ Imagine them written one below another like a grid. Example: cba daf ghi We check column by column. Column 0 → c d g → sorted ✅ Column 1 → b a h → NOT sorted ❌ Column 2 → a f i → sorted ✅ So we delete column 1 → answer = 1 🛠️ Key Observation ✅ A column is sorted if characters do not decrease from top to bottom. That means: 📌 strs[0][col] <= strs[1][col] <= strs[2][col] <= ... ✅ If any pair breaks this rule, that column must be deleted. 🚀 Algorithm 🔷 Take number of rows n 🔷 Take the n strings 🔷 For each column 🔷 Compare every row with the next row 🔷 If upperRowChar > lowerRowChar, mark it as invalid 🔷 Count how many columns are invalid #LeetCode #Java #StringHandling #CodingPractice #ProblemSolving #DSA #DeveloperJourney #TechLearning
To view or add a comment, sign in
-
-
#200DaysOfCode – Day 117 Subsets (Power Set) using Bit Manipulation Problem: LeetCode 78 – Subsets Task:- Given an integer array of unique elements, return all possible subsets (the power set). Example: Input: nums = [1, 2, 3] Output: [[], [1], [2], [1,2], [3], [1,3], [2,3], [1,2,3]] My Approach (Bit Manipulation): Observed that for an array of size n, total subsets = 2^n. Used numbers from 0 to (2^n - 1) as binary masks. Each bit position represents whether an element is included (1) or excluded (0) in the subset. Iterated through each mask and built subsets accordingly. Complexity: Time Complexity: O(n * 2^n) Space Complexity: O(2^n) Bit manipulation is not just about low-level tricks it can provide elegant and efficient solutions to problems like generating subsets. Once you see the binary pattern, the solution becomes surprisingly intuitive. #LeetCode #Java #BitManipulation #DSA #ProblemSolving #TakeUForward #CodingJourney #200DaysOfCode #PowerSet #CleanCode
To view or add a comment, sign in
-
-
Day 33/100 – LeetCode Challenge ✅ Problem: #1292 Maximum Side Length of a Square with Sum Less than or Equal to Threshold Difficulty: Medium Language: Java Approach: Prefix Sum + Binary Search on Square Size Time Complexity: O(m × n × log(min(m, n))) Space Complexity: O(m × n) Key Insight: Use 2D prefix sum to quickly compute sum of any square submatrix in O(1). For each cell, binary search the maximum square side length starting at that cell with sum ≤ threshold. Solution Brief: Built prefix sum matrix psum for O(1) submatrix sum queries. For each possible starting cell, used binary search to find largest valid square. Tracked global maximum side length across all positions. Optimizing submatrix queries with prefix sum. #LeetCode #Day33 #100DaysOfCode #BinarySearch #Java #Algorithm #CodingChallenge #ProblemSolving #MaxSquareSide #MediumProblem #PrefixSum #Matrix #Optimization #DSA
To view or add a comment, sign in
-
-
Day 47/50 of #50DaysOfDSA 🚀 Today’s focus was on string manipulation and stack-based logic with LeetCode 1614 — Maximum Nesting Depth of the Parentheses. The Problem: Given a valid parentheses string, the goal is to find the maximum nesting depth. My Approach: Instead of using an actual stack data structure, I used a simple counter to track the current depth: Increment the counter when encountering ( Decrement when encountering ) Track the maximum value the counter reaches during the iteration. The Result: ✅ Runtime: 0 ms (Beats 100.00% of Java submissions!) ✅ Complexity: O(n) time and O(1) space. It’s satisfying to see how a simple linear scan can be so performant. Almost at the finish line! 🏁 #DSA #CodingChallenge #Java #LeetCode #ProblemSolving #SoftwareEngineering #Day47
To view or add a comment, sign in
-
-
🚀 Day 72 of #100DaysOfCode Solved LeetCode Problem #2977 – Minimum Cost to Convert String II ✅ This was a more advanced follow-up that required handling string-level transformations efficiently. The challenge was to minimize the total cost by choosing optimal substring conversions rather than single-character changes. Key Learnings: -> Using a Trie to store and index valid string transformations -> Modeling transformation costs with dynamic programming -> Combining Trie traversal + DP for efficient substring matching -> Carefully managing state transitions to avoid unnecessary recomputation Language Used: Java -> Runtime: 209 ms (Beats 34.88%) -> Memory: 48.68 MB (Beats 18.60%) Step by step, leveling up problem-solving depth and string algorithm intuition 🚀 #LeetCode #DynamicProgramming #Trie #Java #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 3 of Daily DSA 🚀 Solved LeetCode 1: Two Sum Approach: Used a HashMap to store numbers with their indices. For each element, checked if the complement (target - current) already exists. Complexity: • Time: O(n) • Space: O(n) Performance: Runtime: 2 ms (Beats 99.15%) Memory: 47.34 MB Focusing on writing clean and efficient solutions before over-optimizing. Consistency > Intensity 💯 #DSA #LeetCode #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
#PostLog116 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 556 | 𝐍𝐞𝐱𝐭 𝐆𝐫𝐞𝐚𝐭𝐞𝐫 𝐄𝐥𝐞𝐦𝐞𝐧𝐭 𝐈𝐈𝐈 (𝐉𝐚𝐯𝐚) 𝐍𝐞𝐱𝐭 𝐆𝐫𝐞𝐚𝐭𝐞𝐫 𝐄𝐥𝐞𝐦𝐞𝐧𝐭 𝐈𝐈𝐈 using a 𝐧𝐞𝐱𝐭 𝐩𝐞𝐫𝐦𝐮𝐭𝐚𝐭𝐢𝐨𝐧–𝐛𝐚𝐬𝐞𝐝 𝐚𝐩𝐩𝐫𝐨𝐚𝐜𝐡, ensuring optimal time complexity and clean logic. 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 𝐢𝐧 𝐛𝐫𝐢𝐞𝐟: ~ Traverse from right to left to find the first decreasing digit (pivot) ~ Identify the smallest digit greater than the pivot on the right side ~ Swap them to form a larger number ~ Reverse the suffix to get the smallest possible greater permutation ~ Carefully handle 32-bit integer overflow #LeetCode #Java #DataStructures #Algorithms #ProblemSolving #CodingJourney
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