✅ Day 128 – GeeksforGeeks 160 Days of DSA Challenge Hi everyone, Today’s challenge was Total Decoding Messages — a classic Dynamic Programming problem based on string decoding and combinatorial counting. 🧩 Problem: A numeric string digits represents an encoded message where 'A' -> 1, 'B' -> 2, … 'Z' -> 26. The task is to determine how many possible ways the string can be decoded into letters. For example, "123" can be decoded as "ABC", "LC", or "AW", giving 3 possible decodings. 💡 Logic: We use a DP array dp[i] representing the number of ways to decode up to the i-th digit: If the current digit is not '0', it can stand alone → add dp[i-1]. If the last two digits form a number between 10 and 26, they can form a valid letter → add dp[i-2]. Base cases: dp[0] = dp[1] = 1 (a single non-zero digit has one decoding). This approach ensures O(n) time complexity with O(n) space — an elegant DP solution handling all edge cases like leading zeros or invalid pairs. #GeekStreak2025 #GFG160 #DSA #DynamicProgramming #ProblemSolving #StringDecoding #CodingChallenge #Python
Total Decoding Messages: A DP Solution
More Relevant Posts
-
🚀 Leetcode #3289. The Two Sneaky Numbers of Digitville Recently, I solved an interesting problem focused on detecting duplicate elements in a list of integers. 💡 Problem Statement: Given an integer array nums, return all elements that appear exactly twice. 🔍 Approach: - Initialize a boolean list seen to track whether each number has been encountered. - Traverse the array once: - If a number is already marked as seen, append it to the result list. - Otherwise, mark it as seen. - Return the list containing all duplicate values. ⚙️ Complexity: - Time: O(n) - Space: O(n) ✨ Key Takeaways: - Boolean tracking arrays provide an efficient alternative to hash maps for frequency detection. - Maintaining clean traversal logic helps achieve clarity and optimal performance. #Python #DataStructures #Algorithms #Coding #ProblemSolving #LeetCode #Programming #Efficiency #DSA
To view or add a comment, sign in
-
-
🔥 Day 137 of 160 – GeeksforGeeks #gfg160 DSA Challenge 🔥 🎯 Problem: Maximize partitions in a String 🧠 Approach: This is a classic greedy string problem, also known as "Partition Labels." The goal is to partition the string into the maximum number of parts such that no character appears in more than one part. Preprocessing: First, I did a pass over the string to find the last occurrence index for every character. Greedy Partitioning: I iterated through the string using a pointer i. I also maintained a variable end to track the "end" of the current partition. At each character s[i], I updated end to be the maximum of its current value and the last_occurrence[s[i]]. This "stretches" the current partition to include the last appearance of s[i]. The key insight: When my iterator i finally reaches the end of the current partition, it means every character seen within this partition also ends within it. This signifies a valid partition, so I incremented the count. ✅ 1120 / 1120 test cases passed ⚡ Accuracy: 100% 🏆 Points Scored: 2 / 2 🕒 Execution Time: 0.19s 🔑 Key Learning: This problem is a fantastic example of a greedy interval-based approach. The strategy is to extend the current "window" to the farthest reach of any character it contains. When the loop index catches up to that farthest reach, a minimal, complete partition has been found. 💪 Progress Update: Day 137 is complete! A very clean and clever greedy algorithm. Let's keep the streak going! 🚀 Next ➡️ Day 138 – On to the next challenge! #Day137 #GeeksforGeeks #gfg160 #DSA #CodingChallenge #Python #ProblemSolving #GreedyAlgorithm #String #100DaysOfCode #Programmer
To view or add a comment, sign in
-
-
Space Complexity — The Memory Side of DSA 💾 Your code may be fast… but is it memory-smart? 💾 When I first learned about Time Complexity, I thought speed was everything. But then I realized — what’s the point of fast code if it eats up all your memory? 🧠 That’s where Space Complexity comes in. It measures the extra or auxiliary memory your algorithm uses — beyond the input itself. Let’s simplify it 👇 O(1) → Constant space → One notebook O(n) → Linear space → One notebook per subject O(n²) → Quadratic space → Notes inside each notebook 😅 Here’s a small example: arr = [1, 2, 3, 4, 5] for i in arr: print(i) # O(1) new_arr = arr.copy() # O(n) The first loop uses constant space, while copying the list creates a new array, using linear space. So next time you code, remember — A program isn’t truly efficient unless it’s both fast and memory-smart. Good programmers write code that’s fast. Great programmers write code that’s fast and memory-efficient. 💡 what do you say about this shaheen shaik and Rafique Khan and Sumit Saini share your thoughts in comments.. Notes link: https://lnkd.in/gKMz7jT7 #LearnDSA #HitXCode #CodingJourney #ProgrammingCommunity #SpaceComplexity #Python #DSA
To view or add a comment, sign in
-
🚀 Day 87/100 of the #100DaysOfCode Challenge! #Day87 of #100Dayscodingchallenge:Today's focus was on mastering control flow and precision with nested loops in Python. I tackled a series of classic pattern problems that are fantastic for understanding logical structuring and boundary conditions. The Challenge: Build hollow geometric patterns using only for loops and conditional statements. Patterns Solved: ✅ Hollow Pyramid: A test of symmetry and managing increasing spaces. ✅ Hollow Right-Angled Triangle: Focusing on the first and last elements of each row. ✅ Inverted Hollow Pyramid: The reverse logic of its upright counterpart. ✅ Hollow Diamond: Combining the logic of both the standard and inverted pyramids for a complex, symmetrical shape. These exercises are more than just printing stars; they're about sharpening problem-solving skills, breaking down complex problems into manageable steps, and writing efficient, clean code. It's a powerful reminder that solid fundamentals in loops and conditionals are the building blocks for more advanced algorithms. Check out the code snippet in the comments! 👇 #Nxtwave #ccbp #intensive #Python #Programming #CodingChallenge #Algorithms #ProblemSolving #SoftwareDevelopment #LearnToCode #CodeNewbie #Developer #ProgrammingPatterns
To view or add a comment, sign in
-
✅Day 83 of #100DaysOfLeetCode 1.📌Problem: Find the Pivot Integer Given a positive integer n, find the pivot integer 𝑥 such that the sum of all elements between 1 and 𝑥 inclusively equals the sum of all elements between 𝑥 and n inclusively. Return the pivot integer 𝑥. If no such integer exists, return -1. 2.🟢 Difficulty: Easy 3.📍Topic: Arithmetic & Basic Reasoning 4.🎯 Goal: Identify the integer x where the sum of numbers before and after (including) 𝑥z are equal for a given range.image.jpg 5.🧠Key idea: Approach 1: Find the total sum of numbers from 1 to n using 𝑛(𝑛+1). Incrementally compute the prefix sum from 1 up to 𝑖 and compare it with the suffix sum from 𝑖 to n. If prefix sum equals suffix sum for any i, that 𝑖 is the pivot integer; otherwise, return -1. #LeetCode #100DaysOfCode #CodingChallenge #Programming #DataStructures #Algorithms #CodingJourney #LearningJourney #GrowthMindset #ProblemSolving #DeveloperCommunity #Python #Java #SoftwareEngineering #TechCareersbest
To view or add a comment, sign in
-
-
Day:79/100 Recursion of Palindrome section ✅️ #100daysofcodingchallenge Recursion: ✔️Function calls itself: A function invokes itself repeatedly until a base case is reached. ✔️Base case: A condition that stops the recursion. ✔️Recursive case: The function calls itself with a smaller input or a modified version of the original input. ✔️Stack overflow: A potential risk if recursion is too deep. ✔️Memoization: Caching results to avoid redundant calculations. ✔️Tail recursion: A special case where the recursive call is the last operation. ✔️Base case: Empty or single-character strings are palindromes. ✔️ Recursive case: Compare first and last characters, then recurse on the substring. ✔️Symmetry: Palindromes have symmetry around their center. Benefits: 🔸️ Elegant code: Recursion can make the code more concise and readable. 🔸️ Easy to implement: Recursive palindrome checks can be simple to understand and implement. #Nxtwave #Intensive #100dayscoding #Python #Tech #coding #Programming #TechSkills #CareerDevelopment #DataLiteracy #BusinessIntelligence
To view or add a comment, sign in
-
🔥 Day 141 of 160 – GeeksforGeeks #gfg160 DSA Challenge 🔥 🎯 Problem: Detect Cycle in an Undirected Graph 🧠 Approach: Solved this fundamental graph problem using Breadth-First Search (BFS). The key is to track not just visited nodes, but also their parent in the traversal. I used a queue storing (node, parent) pairs. When processing a node, I check its neighbors. If a neighbor is unvisited, I mark it visited and add it to the queue with the current node as its parent. If a neighbor is already visited, I check if it's the parent of the current node. If it is not the parent, it means we've found a path back to an already visited node, and a cycle exists. ✅ 111 / 111 test cases passed ⚡ Accuracy: 100% 🏆 Points Scored: 4 / 4 🕒 Execution Time: 2.01s 🔑 Key Learning: This BFS approach is a clean way to detect cycles in an undirected graph. The (node, parent) tuple is a crucial piece of information. It allows us to distinguish between a legitimate "parent" edge (which doesn't form a cycle) and a "back-edge" to an already visited node (which does). 💪 Progress Update: Day 141 is complete! A core graph algorithm. Ready for the next challenge! 🚀 Next ➡️ Day 142 – Find the number of islands #Day141 #GeeksforGeeks #gfg160 #DSA #CodingChallenge #Python #ProblemSolving #Graph #BFS #CycleDetection #100DaysOfCode #Programmer
To view or add a comment, sign in
-
-
🚀Day 56 of #100DaysOfCode 🚀Solved LeetCode Problem 3347 – Maximum Frequency of an Element After Performing Operations II (Hard) This problem tested efficient use of sorting + sliding window technique to maximize element frequency after limited operations. The challenge was to determine how far we can extend a subarray where values can be adjusted within a range [-k, k] using at most num Operations modifications — achieving an optimized O(n log n) approach. Runtime: 266 ms — Beats 98.39% Memory: 31.96 MB — Beats 95.16% Key Concepts: Sorting for value proximity alignment Two-pointer technique for maintaining valid operation windows Cumulative operation cost calculation to ensure feasibility Feeling great to see consistent performance improvements and algorithmic clarity growing day by day! 🚀 #LeetCode #100DaysOfCode #Python #ProblemSolving #DataStructures #Algorithms
To view or add a comment, sign in
-
-
✅ Day 52 – GFG 160 Days of Problem Solving Challenge 💡 Problem: Count Pairs with Sum Less Than Target on GeeksforGeeks At first, I tried using two nested loops to check all pair combinations — but that took O(n²) time and wasn’t optimal. 🧠 Optimized Approach (Two-Pointer Technique): Sort the array. Use two pointers — left starting at 0 and right at the end. If arr[left] + arr[right] < target, then all pairs between left and right are valid, so increment count by (right - left) and move left forward. Else, move right backward. This approach brings down the time complexity to O(n log n) (due to sorting) + O(n) for the two-pointer scan. 🔥 Result: Solved all 1108/1108 test cases successfully in 0.07 sec with 100% accuracy! 🚀 ✨ Takeaway: The two-pointer method turns brute-force logic into efficient, elegant solutions — perfect for problems involving pair or triplet sums! Onwards to Day 53! 💪 #DSA #GeeksforGeeks #ProblemSolving #Python #TwoPointer #Optimization #CodingChallenge #160DaysOfCode #Day52
To view or add a comment, sign in
-
-
🧠 Day 25 Theme: Recursion & Backtracking Concepts Covered Recursive calls and base conditions Decision tree and state-space exploration Backtracking for constraint satisfaction Handling duplicates and pruning branches Classic examples: combinations, permutations, subsets, and N-Queens 📚 Learn from These Resources 📘 Recursion Fundamentals 👉 https://lnkd.in/gPQvuduf 👉 https://lnkd.in/gt-mteqM 📗 Backtracking Algorithms 👉 https://lnkd.in/gaRCKvJT 👉 https://lnkd.in/g87eEpKa 📙 Visual Demos & Tutorials 👉 https://lnkd.in/g8FWB-Mq 👉 https://lnkd.in/g6Rt5zgf 🧩 Practice Ideas Generate all subsets of an array Solve permutations of numbers or strings N-Queens / Sudoku solver (classic backtracking) Word search (DFS + backtracking combo) Combinations that sum to target (like Combination Sum I/II) #75DaysOfKnowledge #Recursion #Backtracking #ProblemSolving #CodingJourney #LeetCode #AlgorithmicThinking #Java #Python #Programming
To view or add a comment, sign in