🚀 [Day 17/30] Coding Challenge with @Educative.io 💻 💡 Problem: Split Array Largest Sum Today’s challenge was an interesting mix of binary search + greedy validation. The goal was to split an array into m subarrays such that the largest subarray sum is minimized. The key insight: 👉 If we fix a maximum allowed subarray sum, we can greedily check whether the array can be split into at most m parts. My approach: 1️⃣ Set the search space between max(nums) and sum(nums) 2️⃣ Used binary search to guess the optimal maximum sum 3️⃣ For each guess, greedily counted how many subarrays were needed 4️⃣ Adjusted the search range based on feasibility This turned a complex optimization problem into a clean decision problem.| ✨ Small win: Realizing how “minimize the maximum” problems often map directly to binary search was a big confidence booster. 🔍 Key Learnings: Binary search isn’t just for sorted arrays Greedy checks pair perfectly with binary search Optimization problems often hide feasibility checks #30DaysOfCode #Day17 #CodingChallenge #Educative #DSA #BinarySearch #Greedy #Algorithms #JavaScript #ProblemSolving #InterviewPrep #SoftwareEngineer #LearningInPublic #TechCareers #KeepCoding
Split Array Largest Sum with Binary Search and Greedy Algorithm
More Relevant Posts
-
🚀 [Day 18/30] Coding Challenge with @Educative.io 💻 💡 Problem: Invert Binary Tree Today’s challenge was a classic tree problem — inverting a binary tree by swapping the left and right children of every node. The logic was simple yet powerful: 👉 Traverse the tree and swap left ↔ right at each node. I approached it using recursion: 1️⃣ Swap the left and right child 2️⃣ Recursively apply the same logic to both subtrees This can also be solved iteratively using BFS or DFS, but recursion keeps the solution very clean and readable. ✨ Small win: Problems like this remind me how elegant tree recursion can be — minimal code, clear intent. 🔍 Key Learnings: Tree transformations are often recursive by nature Preorder traversal works well for structural changes Simple problems still reinforce core fundamentals #30DaysOfCode #Day18 #CodingChallenge #Educative #DSA #BinaryTree #Recursion #Algorithms #JavaScript #ProblemSolving #InterviewPrep #SoftwareEngineer #LearningInPublic #TechCareers #KeepCoding
To view or add a comment, sign in
-
Day 8 of 30-day Coding Sprint Today’s focus was on a classic problem that teaches you why linear time isn't always good enough when dealing with exponents. Today's progress on LeetCode: 50. Pow(x, n) The Simple Recursive Approach: Multiplying x by itself n times. - Complexity: O(n) time. - The Issue: For large values of n, this hits the stack limit or simply takes too long. The Optimal Strategy: Binary Exponentiation (Divide & Conquer) - The Logic: Use the property (x^n) = (x^n/2)^2. By halving n at each recursive step, we drastically reduce the number of multiplications. The Result: O(log n) time. This turns a billion operations into roughly 30. #30DaysOfCode #DSASprint #LeetCode #JavaScript #Recursion #Math #Consistency
To view or add a comment, sign in
-
-
Staring at code can sometimes feel like an archaeological dig... or a trip to a coding museum of 'what not to do.' 😅 This gem on "Wages of Inheritance" brilliantly dissects some truly *innovative* (and by innovative, I mean slightly terrifying) approaches to C++ inheritance. Picture this: a base class that knows *everything* about its future children through an enum (because who needs actual polymorphism when you have a crystal ball?), or a base class performing `dynamic_cast` on itself like it's trying to guess its own identity! The result? Mysterious `std::bad_cast` exceptions that leave developers scratching their heads and blaming nasal goblins. 👻 It's a hilarious and cautionary tale reminding us that sometimes, sticking to the well-trodden paths of OOP is less about being boring and more about preventing future headaches (and debugging nightmares!). Let's keep our inheritance hierarchies clean and our code maintainable! What's the most 'unconventional' code you've ever inherited? Share your tales of wonder and woe! 👇 If this coding adventure made you smile (or sigh in recognition), give it a like, share it with your developer friends, and follow for more relatable tech insights and a good laugh! #ProgrammingHumor #Cpp #SoftwareDevelopment #CodingFails #Inheritance #TechInsights #DeveloperLife #CodeReview Read more: https://lnkd.in/gxk2zxvx
To view or add a comment, sign in
-
-
✨TypeScript's any vs unknown — Which one do you use? Most of us grab any for quick fixes, but it can hide bugs until runtime. unknown forces validation, making your code safer from the start. It's not about more typing. It's about writing smarter, more reliable code. 👉 Want the simple breakdown? I covered any, unknown, null, and undefined with clear examples here: https://lnkd.in/g9i8xSWr #TypeScript #WebDevelopment #ProgrammingTips #Coding #JavaScript #FullStackDevelopment
To view or add a comment, sign in
-
Day 4/30 – Namaste DSA in JavaScript 🚀 Here’s what I covered: Second Largest Element in an Array - Continuing my DSA Learning Journey by writing logic to find the second largest element in a list/array. - This problem helped strengthen my understanding of comparisons, iterations, and tracking values while looping through arrays. - Learned how careful condition checks and efficient traversal can solve problems without unnecessary complexity. #30DaysOfCode #LearningJourney #DSA #ProgrammingBasics #Upskilling #NamasteDev #FrontendDevelopment #CodingJourney #WebDevelopment #LearningInPublic
To view or add a comment, sign in
-
𝗪𝗲𝗹𝗰𝗼𝗺𝗲 𝘁𝗼 𝗗𝗮𝘆 𝟭𝟯 𝙃𝙤𝙬 𝙅𝙖𝙫𝙖𝙎𝙘𝙧𝙞𝙥𝙩 𝙂𝙖𝙧𝙗𝙖𝙜𝙚 𝘾𝙤𝙡𝙡𝙚𝙘𝙩𝙞𝙤𝙣 𝙒𝙤𝙧𝙠𝙨 Your code doesn’t free memory. JavaScript does. But it only removes what is unreachable. 𝙍𝙚𝙖𝙘𝙝𝙖𝙗𝙞𝙡𝙞𝙩𝙮 An object stays in memory if there is a reference path from the roots. Roots: • Global scope • Execution stack • Active closures No path → eligible for garbage collection. 𝙈𝙖𝙧𝙠 & 𝙎𝙬𝙚𝙚𝙥 • Start from the roots and mark all reachable objects • Remove everything unmarked Reachable stays. Unreachable is freed. 𝙂𝙚𝙣𝙚𝙧𝙖𝙩𝙞𝙤𝙣𝙖𝙡 𝘾𝙤𝙡𝙡𝙚𝙘𝙩𝙞𝙤𝙣 Most objects die young. Memory is divided into: • Young generation → short-lived objects, frequent fast cleanup • Old generation → long-lived objects, less frequent cleanup 𝙋𝙧𝙤𝙢𝙤𝙩𝙞𝙤𝙣 Every object starts in the young generation. If it survives multiple GC cycles or memory pressure increases, it gets promoted to the old generation. Survival determines placement. 𝙒𝙝𝙮 𝙈𝙚𝙢𝙤𝙧𝙮 𝙇𝙚𝙖𝙠𝙨 𝙎𝙩𝙞𝙡𝙡 𝙃𝙖𝙥𝙥𝙚𝙣 GC removes only unreachable objects. Leaks occur when references are retained: • Globals • Closures • Timers / event listeners • Growing caches 𝘎𝘊 𝘸𝘰𝘳𝘬𝘴 𝘤𝘰𝘳𝘳𝘦𝘤𝘵𝘭𝘺. 𝘠𝘰𝘶𝘳 𝘳𝘦𝘧𝘦𝘳𝘦𝘯𝘤𝘦𝘴 𝘥𝘦𝘤𝘪𝘥𝘦 𝘸𝘩𝘢𝘵 𝘭𝘪𝘷𝘦𝘴. #JavaScript #WebDevelopment #SoftwareEngineering #FrontendDevelopment #Programming #Coding #Developers #TechCommunity #ComputerScience #PerformanceOptimization #Learning #ContinuousLearning #LearnInPublic
To view or add a comment, sign in
-
-
“Bug exists. Me: WHY THO??” Debugging didn’t just teach me code — it taught me patience when nothing works, logic when emotions want control, and humility when the smallest mistake breaks everything. Every error is a lesson. Every fix is growth. Some days you write perfect logic… and still, the bug exists. You question your code, your skills, even yourself. But slowly, debugging teaches you something deeper than syntax. It teaches you to pause instead of panic. To think instead of react. To accept that being wrong is part of becoming better. Coding humbles you. #BugExists #DebuggingLife #ProgrammerHumor #CoderMindset #DeveloperLife #CodeNewbie #TechLife #LearningToCode #CodingStruggles #LogicOverEmotion #GrowthThroughFailure #MentalHealthInTech #PatienceIsPower #DailyDebug #BuildInPublic
To view or add a comment, sign in
-
-
Day 4 of 30-day Coding Sprint Today was a deep dive into Maximum Product Subarray—a classic problem that looks simple until you hit zeros and negative numbers. Today's progress on Leetcode: 152. Maximum Product Subarray - The Brute Force: Nesting loops to check every single subarray. At O(N^3) (or O(N^2) with optimization), it's too much for large datasets. - The Observation: Unlike sums, products are volatile. A single zero resets everything, and a negative number can turn a tiny product into a maximum (or vice versa). - The Optimal Strategy (Prefix & Suffix): By calculating products from both the front (Prefix) and the back (Suffix), you naturally handle the "even vs. odd" negative number count. The Zero Reset: Whenever a product hits 0, I reset to 1 to start a fresh subarray. Result: Clean O(N) time complexity with O(1) space. #30DaysOfCode #DSASprint #LeetCode #JavaScript #Algorithms #Optimization #Consistency
To view or add a comment, sign in
-
-
Vibe coding just wasn't cutting it for me. Developers think in code, not paragraphs! So I invented Shadow Coding! 🚀 Compared to vibe coding, Shadow Coding gives a higher-quality output using fewer input tokens, all while using a free open-source model! 🤯 How does it achieve this? Easy... Shadow Coding let's you prompt with code instead of plain English! Check it out: - Watch The YouTube Video: https://lnkd.in/dkZBwd4i - GitHub Link: https://lnkd.in/db5UJVNA #ai #vibecoding #coding #claude #claudecode #vscode #programming #aicoding #cursor #dev
To view or add a comment, sign in
-
-
Revisiting Linked Lists to strengthen my DSA fundamentals 📌 Today, I went back to one of the most important data structures — Linked Lists — and solved the Linked List Cycle problem on LeetCode. I used Floyd’s Tortoise and Hare algorithm, which detects cycles efficiently using two pointers moving at different speeds without using extra memory. 🔍 Key Learnings: How fast and slow pointers help identify a cycle Why this approach runs in O(n) time and O(1) space The importance of revisiting fundamentals to build strong problem-solving skills Revising core concepts is helping me improve clarity and confidence step by step. #DSA #LinkedList #LeetCode #JavaScript #ProblemSolving #MasaiSchool #MasaiJourney #MasaiStudent #LearningAtMasai #BuildInPublic
To view or add a comment, sign in
-
Explore related topics
- Approaches to Array Problem Solving for Coding Interviews
- Prioritizing Problem-Solving Skills in Coding Interviews
- Strategies for Solving Algorithmic Problems
- Solving Sorted Array Coding Challenges
- Tips for Overcoming Coding Learning Challenges
- Tips for Mastering Algorithms
- LeetCode Array Problem Solving Techniques
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