Leetcode Biweekly 172 - solved 𝟑/𝟒 problems. I started 𝟐𝟎 𝐦𝐢𝐧𝐮𝐭𝐞𝐬 𝐥𝐚𝐭𝐞 due to the server and network error, still manage to solve 3/4 problems 𝐰𝐢𝐭𝐡𝐢𝐧 𝟑𝟖 𝐦𝐢𝐧𝐮𝐭𝐞𝐬 after start. Here is my solution: 1️⃣ Create a map to count the frequency of each element and create a multiset to store the current highest frequency element. Now we will traverse our vector, since we have to remove the first 3 elements so at every i % 3 == 0, we will check if the highest frequency == 1 means all elements are distinct and we can break else increment ans and we will erase the current element's frequency from multiset, decrement it in the map, and reinsert its updated frequency into the multiset. 2️⃣ A cakewalk number theory problem for a CF solver. As we know, the sum of three elements will be divisible by 3 if sum of their modulo with 3 is divisible by 3. So, we need to create three vectors which store elements with modulo 0, 1, and 2 respectively and sort them in descending order, and try these combinations - three 0s, three 1s, three 2s, and one 0, one 1, and one 2 modulo element and take max of them as ans. 3️⃣ The main observation is that we can't move '1' towards the right and can only move it towards the left, so it will be optimal if '1' will be in front of the current largest number of the vector towards the left side. To keep track of it, we will use a priority queue(pq). We will traverse the string and push corresponding vector elements into the pq, and whenever we have '1' in the string, we will add the top element of the pq to ans and pop it. Although my yesterday Codeforces round was not gone well, but 𝐭𝐡𝐞 𝐛𝐞𝐬𝐭 𝐩𝐚𝐫𝐭 𝐚𝐛𝐨𝐮𝐭 𝐜𝐨𝐦𝐩𝐞𝐭𝐢𝐭𝐢𝐯𝐞 𝐩𝐫𝐨𝐠𝐫𝐚𝐦𝐦𝐢𝐧𝐠 𝐢𝐬 𝐭𝐡𝐚𝐭 𝐞𝐯𝐞𝐫𝐲 𝐜𝐨𝐧𝐭𝐞𝐬𝐭 𝐠𝐢𝐯𝐞𝐬 𝐲𝐨𝐮 𝐚 𝐟𝐫𝐞𝐬𝐡 𝐬𝐭𝐚𝐫𝐭 𝐚𝐧𝐝 𝐚 𝐧𝐞𝐰 𝐜𝐡𝐚𝐧𝐜𝐞 𝐭𝐨 𝐜𝐨𝐦𝐞 𝐛𝐚𝐜𝐤. #coding #leetcode #competitiveprogramming
Leetcode Biweekly 172 - 3/4 problems solved in 18 minutes
More Relevant Posts
-
Hello connections, Here is my solution to a LeetCode dynamic programming problem. Time Complexity: O(N × M) Space Complexity: O(N × M) Learning from the problem: This problem requires carefully handling negative values while ensuring that at least one pair of elements is selected. By using dynamic programming and considering whether to take or skip elements from either array, we can build the maximum dot product step by step. A key insight is extending a subsequence only when it improves the total, otherwise starting fresh with the current pair. This is a great example of how DP helps manage multiple choices and constraints simultaneously. #leetcode #problemsolving #cpp #dynamicprogramming #arrays #datastructures #happycoding
To view or add a comment, sign in
-
-
“Error on line 265.” So you scroll. Line 265 is empty. No code. No mistake. Just you… staring. That quiet pause where you start doubting: the editor the code your decision to learn programming And then it hits you— the problem was never that line. It was the bracket you missed earlier. The function you thought you closed. The typo you ignored because “it looks fine”. Every developer knows this moment. The sigh. The re-read. The slow scroll upward. Debugging isn’t fixing errors. It’s having patience with yourself while you figure out where you went wrong. And somehow… that’s where most of the learning actually happens. #DevelopersLife #Debugging #CodingJourney #LearnToCode #DeveloperCommunity
To view or add a comment, sign in
-
-
🚀 LeetCode Daily Practice – Day 41 Problem: Burst Balloons (Dynamic Programming) Today’s problem was one of those DP challenges where greedy strategies completely fail. The goal is to burst balloons in an order that maximizes the coins collected — but every burst changes the values of its neighbors. 🎯 Core Idea Instead of thinking forward (which balloon to burst next), the trick is to think backwards: Assume every balloon is the last one burst in its interval. By fixing the last burst balloon, the interval splits into two independent subproblems, making DP possible. This converts a chaotic optimization problem into a carefully structured interval DP. 🔍 Why This Problem Is Interesting The order of operations changes everything. Bursting what “looks best now” is often wrong, because later balloons depend on it. DP forces us to evaluate all possibilities without recomputing them, revealing the true optimal order. 🧠 Key Insight Some problems only make sense when viewed from the end instead of the beginning. Interval DP is powerful when decisions inside a range depend on its boundaries. ⏱ Time Complexity → O(n³) 🧠 Space Complexity → O(n²) 🌱 Daily Learning Takeaway When local choices mislead, step back and ask: “What if I decide the final outcome first?” Dynamic programming often starts where intuition ends. #leetcode #dsa #dynamicprogramming #intervaldp #coding #learningeveryday #growthmindset #developer #problemsolving
To view or add a comment, sign in
-
Day 8/100 of my #100DaysOfCode challenge! 🚀 Today's problem: "Minimum Falling Path Sum" - a dynamic programming challenge on LeetCode. 📌 The task: Given an n x n matrix, find the minimum sum of any falling path through the matrix, where from position (i, j) you can move to (i+1, j-1), (i+1, j), or (i+1, j+1). 💡 Key Insight: This is a classic dynamic programming problem where we build the solution row by row. For each cell in the current row, the minimum falling path sum is the cell's value plus the minimum of the three possible parent cells from the previous row. 🔧 Approach: Initialize the first row of DP table with the matrix's first row values For each subsequent row, compute each cell as its value plus the minimum of the three possible cells from the row above The answer is the minimum value in the last row ✅ Time Complexity: O(n²) ✅ Space Complexity: O(n²) (can be optimized to O(n) if needed) #LeetCode #DynamicProgramming #CodingChallenge #Algorithm #ProblemSolving #SoftwareEngineering #CareerGrowth #TechJourney
To view or add a comment, sign in
-
-
🔧 Why I Still Follow the 79‑Character Rule as a Developer In a world of ultra‑wide monitors and modern IDEs, it’s easy to forget the value of small engineering disciplines. One of my favorites is the classic 79‑character line length. It’s not just a “Python thing” - it’s a mindset. It forces clarity It improves readability in terminals, diffs, and reviews It encourages smaller, more focused functions It keeps collaboration smooth across tools and teams As developers, the little habits we build shape the quality of the systems we create. Clean code isn’t about perfection - it’s about intention. If a simple constraint like 79 characters can make code easier to read, maintain, and debug, I’m all for it. Small discipline. Big impact. #CleanCode #CodeQuality #SoftwareCraftsmanship #BestPractices #CodingStandards #DeveloperLife #EngineeringMindset #ProductivityTips #TechDiscipline
To view or add a comment, sign in
-
Just published a new video diving deep into WebAssembly using Rust — built without wasm_bindgen and without the usual abstraction layers. In this walkthrough, I focus on how WebAssembly truly works under the hood: memory, modules, imports/exports, and how the browser actually executes your compiled code. It’s a mix of systems programming, curiosity, and a bit of chaos in the best way 🚀 Watch here: https://lnkd.in/gdy4TGWj If you’re exploring Rust, WebAssembly, or low-level engineering concepts, I’d love to hear your thoughts or questions in the comments 🙂 #Rust #WebAssembly #Wasm #RustLang #SoftwareEngineering #SystemsProgramming #Programming #Developers #LearningInPublic
To view or add a comment, sign in
-
🚀 LeetCode Daily Practice – Day 32 Problem: Minimum ASCII Delete Sum for Two Strings (Dynamic Programming) Today’s problem was about making two strings equal — but instead of counting operations, the cost depends on the ASCII value of the deleted characters. The goal is to minimize the total deletion cost so both strings become identical. 🎯 Core Idea We use dynamic programming to compare prefixes of both strings. If characters match, we keep them. If they don’t, we choose the cheaper option: delete from the first string or delete from the second, and add the ASCII value of the removed character. Step by step, this builds the minimum possible total cost. 🔍 Why This Problem Is Interesting It’s closely related to Edit Distance and LCS, but the twist is cost-based deletion. Instead of counting edits, we optimize based on character values, which adds another dimension to decision-making. 🧠 Key Insight DP shines here because every decision depends on smaller prefix comparisons. Once we define the recurrence properly, the problem becomes systematic rather than trial-and-error. ⏱ Time Complexity → O(m × n) 🧠 Space Complexity → O(m × n) or O(n) with optimization 🌱 Daily Learning Takeaway Optimizing cost is often more complex than counting steps — but dynamic programming gives a structured way to evaluate every possible path efficiently. #leetcode #dsa #dynamicprogramming #strings #coding #learningeveryday #growthmindset #developer #problemsolving
To view or add a comment, sign in
-
Stop writing mid code. 💀 If you’re still using nested loops for every subarray problem, your runtime is literally crying. We’re moving from O(N^2) stress to O(N) energy with the Two Pointers glow-up. ⚡️ The TL;DR: •Two Pointers: Moving different directions (main character energy). •Sliding Window: For those continuous segments (no gatekeeping). Don't let your complexity be "too much." Check the slides to level up. 🧠 Practice challenge in the last slide! 📌 https://lnkd.in/gE4YJu4J #Coding #SoftwareEngineer #TwoPointers #LeetCode #GlowUp #ProgrammingTips #TechTok
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