Maximizing Array Sum After K Negations, Gas Station Problem, and Candy Distribution

Maximizing Array Sum After K Negations Given an integer array, we can perform K operations where each operation flips the sign of an element. The goal is to maximize the sum after exactly K operations. Approach: Sort the array by absolute values in descending order Flip negative numbers first too maximize sum gains If remaining operations are ...

Posted on Wed, 26 Aug 2026 16:26:56 +0000 by A3aan

Greedy Strategies for Change Making, Queue Reconstruction, and Bursting Balloons

Lemonade Change Problem A lemonade stand sells each cup for $5. Customers pay with either a $5, $10, or $20 bill, and you must provide exact change for each transaction, starting with no cash on hand. Determine whether you can serve all customers successful. The approach becomes straightforward once we identify three scenarios: Customer pays $ ...

Posted on Mon, 27 Jul 2026 16:38:09 +0000 by iBlizz

Greedy Algorithms in Practice: Assigning Cookies, Longest Wiggle Subsequence, and Maximum Subarray

Fundamentals of Greedy Strategies Greedy algorithms do not follow a rigid template. They essence lies in building a global optimum through a sequence of locally optimal choices. While formal proof of correctness is not mandatory for competitive programming (as long as the solution is accepted), a systematic approach helps: Break the problem in ...

Posted on Tue, 14 Jul 2026 16:22:43 +0000 by hunna03

Solving LeetCode Problems Using Greedy Strategies

1648. Sell Diminishing-Valued Colored Balls The objective is to maximize profit when selling balls whose values decrease by 1 after each sale. The optimal approach is a greedy strategy where we always sell the currently most valuable balls available. By sorting the inventory in descending order, we can visualize the stock as columns. We process ...

Posted on Fri, 26 Jun 2026 16:49:48 +0000 by keystroke

Greedy Algorithm Applications: Common Problem Solutions

Longest Encreasing Subsequence The problem can be solved using a greedy approach by maintaining a sequence that represents the smallest possible tail value for all increasing subsequences of each length. The key insight is that for any increasing subsequence, if we encounter a number that's smaller than the current tail of our sequence, we can ...

Posted on Sat, 16 May 2026 11:27:09 +0000 by mrherman