🚀 Cracked a Powerful LIS Variant Today While practicing Dynamic Programming (LIS patterns), I came across a really interesting problem that pushed me to think beyond the standard approach. The twist? Instead of applying LIS directly on the whole array, the problem required: * Splitting the array into **k independent subsequences** * Solving each subsequence separately * And optimizing using **Longest Non-Decreasing Subsequence (LNDS)** with binary search Key Insight: When constraints are large, a naive DP (O(n²)) won’t work. You need to switch to an **O(n log n)** approach using the patience sorting technique. What I learned: * How to **identify hidden LIS patterns** * Difference between **LIS vs LNDS (strict vs non-decreasing)** * Importance of **problem transformation (splitting into k groups)** * Writing **efficient, contest-ready code** This kind of question is a great example of how: > A classic DP concept + smart observation = optimized solution Really enjoying diving deeper into CP patterns for upcoming contests like HackWithInfy #DataStructures #Algorithms #DynamicProgramming #LIS #CompetitiveProgramming #CodingJourney #HackWithInfy
Cracking LIS Variant with LNDS and Binary Search
More Relevant Posts
-
Practiced an interesting array problem today: Majority Element. What I understood from this problem was that not all meaningful learning comes from complex topics like dynamic programming or backtracking. Sometimes, even simpler problems create room to think more deeply about optimization. This problem has a very straightforward solution using hashing, but it also led me to explore how much the solution could be optimized in terms of space. That’s when I came across the Boyer–Moore Majority Vote Algorithm. The idea behind it is quite intuitive. Instead of explicitly counting every element, we maintain a candidate and a counter . As we iterate through the array, matching elements increase the count, while different elements decrease it. Over time, elements effectively "cancel each other out". Since the majority element appears more than ⌊n/2⌋ times, it ends up being the final candidate after all cancellations. Problems like this are a good reminder that sometimes the real value lies not just in solving a problem, but in exploring how far an idea can be optimized. ⚡ #softwareengineering #leetcode #algorithms #dsa #coding #programming #problemSolving #computerscience
To view or add a comment, sign in
-
-
Day-28 Solved the Count and Say problem today and it turned out to be a really good exercise in string manipulation. 👉 The idea is simple: start with "1" and keep generating the next term by describing the previous one. 👉 You only count consecutive digits, not overall frequency. 👉 Example: "1" → "11" → "21" → "1211" 💡 What I learned: Always think in terms of patterns Handle edge cases carefully (especially index bounds ⚠️) Small bugs like accessing i+1 without checking can break everything 🛠️ Concepts used: Strings Loops to_string() It looked confusing at first, but once the pattern clicked, it became straightforward. #leetcode #cpp #dsa #coding #learning
To view or add a comment, sign in
-
-
Problem: Partitioning Into Minimum Number of Deci-Binary Numbers 🔍 What is the problem? You are given a number n as a string. You need to split it into minimum deci-binary numbers such that: Each number contains only 0 and 1 Their sum equals n 🧠 Key Idea (Core Logic) 👉 Each digit in n represents how many times 1 is needed at that position. So instead of building numbers: ✅ The answer is the maximum digit in the string 🔄 Step-by-Step Dry Run Example 1: n = "32" Step 1: Convert string into array arr = ['3', '2'] count = 0 Step 2: Start loop We reduce all non-zero digits by 1 in each iteration 🔁 Iteration 1: Before: 3 2 After : 2 1 (each non-zero digit reduced by 1) count = 1 🔁 Iteration 2: Before: 2 1 After : 1 0 count = 2 🔁 Iteration 3: Before: 1 0 After : 0 0 count = 3 🔁 Iteration 4: Before: 0 0 No changes → STOP ✅ Final Answer: count = 3 🔍 What did we observe? Digit 3 required 3 iterations Digit 2 required 2 iterations Final answer = maximum = 3 #DataStructures #Algorithms #DSA #CodingProblems #ProblemSolving #CodingJourney #LearnToCode #ProgrammingLife #CodeDaily #LeetCode
To view or add a comment, sign in
-
-
A webassembly fueled LLM driven programming language? Couple this with spacetimedb's 100,000 transactions per second on a single machine - and I think something interesting could happen. This seems like the origins of a pretty interesting development framework. https://spacetimedb.com/ https://veralang.dev/
To view or add a comment, sign in
-
📌 We learn stacks as a simple concept: Last In, First Out 👉 That makes it easier to recognize using stack as a pattern for problems such as “Parantheses matching” or “Undo/Redo” But then you come across a problem like Daily Temperatures 🌡️ Why would you even think of using a stack here? 🤷♀️ And more importantly — how? 🤔 That’s where the idea of a “Monotonic stack” comes in. 📌 Instead of using a stack just for insertion order, we use it to maintain a condition. 👉 Elements are kept in a specific order (increasing or decreasing) 👉 The moment that order is violated, we start popping So the stack isn’t just storing elements — it’s helping us eliminate unnecessary comparisons and keep only what’s useful ✔️ And that shift is what makes the solution efficient ⚡ Why this problem captures my interest is because: 👉 Not every problem clearly signals the pattern you need, the real skill is identifying which structure helps you track and optimize information efficiently👍 #softwareengineering #leetcode #algorithms #dsa #stack #coding #programming #problemSolving #computerscience
To view or add a comment, sign in
-
-
😱 Most beginners solve this problem in O(N²) or O(N³) But experienced programmers solve it in O(N). The trick? Sliding Window Technique. Let’s understand it with a simple example. Array : 1 2 3 4 5 Window size = 3 Instead of recalculating every subarray like this: [1 2 3] [2 3 4] [3 4 5] We simply slide the window. Old window : [1 2 3] Slide → [2 3 4] Instead of recomputing everything we just : • Remove 1 • Add 4 That’s it. Time Complexity improves from O(N²) → O(N). Key Idea New Window = Previous Window - element leaving + element entering I wrote a detailed explanation with code and visuals here : https://lnkd.in/gKRuKHy8 If you're learning DSA or Competitive Programming, this technique is extremely useful. Follow me for more simple explanations of algorithms #DSA #CompetitiveProgramming #Algorithms #CodingInterview #SlidingWindow #LeetCode #Programming
To view or add a comment, sign in
-
-
🔥 Day 98 of #100DaysOfCode Today’s problem was all about string manipulation and greedy thinking — solving the Alternating Characters challenge. 💡 Problem Summary: Given a string of only A and B, the goal is to make sure no two adjacent characters are the same by deleting the minimum number of characters. 🧠 Approach: Instead of trying all possibilities, I used a simple and efficient strategy: Traverse the string once Compare each character with the previous one If they are the same → increment deletion count ⚡ Key Insight: Every pair of matching adjacent characters contributes exactly 1 deletion. 📊 Complexity: Time: O(n) Space: O(1) 🧪 Example: AAABBB → 4 deletions ABABAB → 0 deletions ✨ What I Learned: Sometimes the simplest greedy approach beats complex logic. Recognizing patterns in strings is a powerful skill in problem-solving! 💻 Language Used: C #Day98 #100DaysOfCode #CodingChallenge #DataStructures #Algorithms #CProgramming #ProblemSolving #DeveloperJourney
To view or add a comment, sign in
-
🚀 DSA Deep Dive – Day 38 Solved Distinct Subsequences today. And I realized… Dynamic Programming is not just about finding answers. Sometimes it’s about counting possibilities under constraints. 🤯 The problem looks simple: Given two strings s and t, find how many subsequences of s equal t. Not substring. Subsequence. That means skipping is allowed… and that’s where complexity begins. 👀 Here’s what I learned 👇 • Define dp[j] = number of ways to form t[0…j-1] • Base case: dp[0] = 1 ✅ (empty string always possible) • Traverse s and update dp backwards At every character, you decide: 👉 Take this character (if it matches) 👉 Or skip it ⚙️ Transition If s[i-1] == t[j-1]: 👉 dp[j] += dp[j-1] Each match adds new ways. Brute force recursion: Exponential 💀 Optimized DP: O(n × m) ⚡ Space optimized: O(m) 🚀 💡 The Powerful Shift Instead of asking “How many subsequences overall?” Ask “How many ways can I build THIS prefix of t?” Build prefix → reach full answer. 🎯 Lesson When counting problems appear: Think in terms of: • Choices (take / skip) • Prefix building • Accumulating ways That’s DP in its purest form. Day by day getting sharper 💪 From solving → to understanding patterns 🚀 Consistency continues. Follow for more DSA breakdowns 🔥 #LeetCode #DSA #DynamicProgramming #InterviewPrep #CodingJourney #ProblemSolving #100DaysOfCode #SoftwareEngineering #TechGrowth
To view or add a comment, sign in
-
-
Day 39/120: Backtracking continues - combinations with pruning One problem today. More practice with backtracking patterns. Target Sum Combinations Find all unique combinations of array elements that sum to a target. Classic backtracking setup: explore each element, add it to current combination, recurse with reduced target. When target reaches zero, save the combination. Backtrack by removing the element. The optimization: sort the array first. During exploration, if an element exceeds the remaining target, break early. All subsequent elements will also be too large. This pruning transformed a slow exhaustive search into something efficient. Same correctness, better performance. What I'm noticing: Backtracking problems follow a template: choose, explore, unchoose. The code structure is remarkably similar across problems - the difference is in what you're choosing and what constraints you're checking. Yesterday was maze paths with visited tracking. Today is combinations with sum constraints. Different problems, same recursive pattern. Thirty-nine days in. The patterns are sticking. #DSA #CodingJourney #100DaysOfCode #LeetCode #GeeksForGeeks #Backtracking #Recursion #Algorithms #SoftwareEngineering #Programming #Learning #Day39
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
Congrats