Given a number N. At every step, subtract the largest perfect square( ≤ N) from N. Repeat this step while N > 0. The task… Read More

# Category Archives: Greedy

Given a string str, the task is to find the length of the longest sub-string which does not have any pair of consecutive same characters. Examples: … Read More

Given an array arr[] of size N. The task is to find the minimum number of changes required to convert the array such that for… Read More

Given two unsorted arrays arr1[] and arr2[]. Find the sum of elements from arr1[] whose difference with the mean of arr2[] is < k.Examples: Input:… Read More

Given three integers N, X, and Y. The task is to find N positive integers that satisfy the given equations. a12 + a22 + ….… Read More

Given two integers N and M. The task is to find the minimum number of steps to reach M from N by performing given operations. … Read More

Given an integer X. The task is to find the number of jumps to reach a point X in the number line starting from zero. Note:… Read More

Given an array arr[] of size n where arr[i] is the number of candies of type i. You have an unlimited amount of money. The… Read More

Given an array arr[] of n integers and an integer k. The task is to maximize the sum of the array after performing the given… Read More

Given an undirected unweighted connected graph consisting of n vertices and m edges. The task is to find any spanning tree of this graph such… Read More

Given a set of N intervals, the task is to find the maximal set of mutually disjoint intervals. Two intervals [i, j] & [k, l]… Read More

Given the count of digits 1, 2, 3, 4. Using these digits you are allowed to only form numbers 234 and 12. The task is… Read More

Given an array of positive and negative elements. The task is to replace every i-th element of the array by the absolute difference of absolute… Read More

Given n number of sorted files, the task is to find the minimum computations done to reach the Optimal Merge Pattern. When two or more sorted… Read More

Given three non-zero integers a, b and c. The task is to find the maximum value possible by putting addition and multiplication signs between them… Read More