Longest Increasing Subsequence problem solution with Binary Search

“My code passed 𝟏𝟎𝟎+ test cases… so I thought I was done.” 😌 Then test case 118 happened. 💀 I was solving the 𝐋𝐨𝐧𝐠𝐞𝐬𝐭 𝐈𝐧𝐜𝐫𝐞𝐚𝐬𝐢𝐧𝐠 𝐒𝐮𝐛𝐬𝐞𝐪𝐮𝐞𝐧𝐜𝐞 (LIS) problem using Dynamic Programming (𝐑𝐞𝐜𝐮𝐫𝐬𝐢𝐨𝐧 + 𝐌𝐞𝐦𝐨𝐢𝐳𝐚𝐭𝐢𝐨𝐧). Everything looked perfect. Clean code. Correct logic. And most importantly — it was passing. Until it didn’t. Large test cases started crashing with runtime errors. That’s when it hit me… 👉 The problem wasn’t my code. 👉 The problem was my thinking. I was using an O(n²) approach for constraints up to 10⁵. No matter how “correct” it is… it’s not scalable. So I switched to the O(n log n) solution using 𝐁𝐢𝐧𝐚𝐫𝐲 𝐒𝐞𝐚𝐫𝐜𝐡. Same problem. Same goal. Completely different performance. 💡 That moment changed how I look at problems: Correct ≠ Efficient Passing ≠ Scalable 𝘿𝙤 𝙮𝙤𝙪 𝙥𝙧𝙞𝙤𝙧𝙞𝙩𝙞𝙯𝙚 𝙘𝙤𝙧𝙧𝙚𝙘𝙩𝙣𝙚𝙨𝙨 𝙛𝙞𝙧𝙨𝙩 𝙤𝙧 𝙨𝙘𝙖𝙡𝙖𝙗𝙞𝙡𝙞𝙩𝙮 ? #DataStructures #Algorithms #DynamicProgramming #CodingJourney #SoftwareEngineering #ProblemSolving #TechLearning #LearnInPublic #Developers #Coding

Scalability comes with correctness.

To view or add a comment, sign in

Explore content categories