Category Archives: Greedy

Paper Cut into Minimum Number of Squares

Given a paper of size A x B. Task is to cut the paper into squares of any size. Find the minimum number of squares that can be cut from the paper. Examples: Input : 13 x 29 Output : 9 Explanation : 2 (squares of size 13×13) + 4 (squares of size 3×3) +… Read More »

Find maximum sum possible equal sum of three stacks

Given three stack of the positive numbers, the task is to find the possible equal maximum sum of the stacks with removal of top elements allowed. Stacks are represented as array, and the first index of the array represent the top element of the stack. Examples: Input : stack1[] = { 3, 10} stack2[] =… Read More »

Maximize array sum after K negations | Set 2

Given an array of size n and a number k. We must modify array K number of times. Here modify array means in each operation we can replace any array element arr[i] by -arr[i]. We need to perform this operation in such a way that after K operations, sum of array must be maximum? Examples:… Read More »

Minimum Cost to cut a board into squares

A board of length m and width n is given, we need to break this board into m*n squares such that cost of breaking is minimum. cutting cost for each edge will be given for the board. In short we need to choose such a sequence of cutting such that cost is minimized. Examples: For… Read More »

Maximize array sum after K negations | Set 1

Given an array of size n and a number k. We must modify array K number of times. Here modify array means in each operation we can replace any array element arr[i] by -arr[i]. We need to perform this operation in such a way that after K operations, sum of array must be maximum? Examples:… Read More »