Skip to content

Category Archives: Greedy

Given an array arr[] consisting of N integers, the task is to find the maximum possible value of the expression (arr[i] * arr[j]) + (arr[j]… Read More
Given an array arr[] consisting of N integers such that arr[i] representing the number of socks of the color i and an integer K, the… Read More
Given an integer N, representing number of projects, two arrays P[] and C[], consisting of N integers, and two integers W and K where, W… Read More
Given two arrays arr[] and S[] consisting of N and K integers, the task is to find the maximum sum of minimum and maximum of… Read More
Given a 2D array arr[][3] consisting of information of N trains where arr[i][0] is the train number, arr[i][1] is the arrival time, and arr[i][2] is… Read More
Given an array arr[] consisting of N integers, the task is to find the minimum number of array elements required to be incremented to make… Read More
Given three positives integers A, B, and C, the task is to count the minimum number of flipping of bits required in A and B,… Read More
Given a string S consisting of N alphabets and two positive integers L and U, representing the cost of converting any character to lowercase and… Read More
Given three non-negative integers A, B, and C, the task is to count the numbers in the range [1, C] that can be reduced to… Read More
Given an array arr[] consisting of N integers, the task is to find the last remaining array element after removing every second element, starting from… Read More
Given a string S of length N, consisting of lowercase characters containing reordered English representations of digits [0 – 9], the task is to print… Read More
Given a positive integer N, the task is to count the number of integers from the range [1, N], that can be represented as ab,… Read More
Given an array weight[] consisting of weights of N items and a positive integer C representing the capacity of each bin, the task is to… Read More
Given an array arr[] consisting of N positive integers and a 2D array Q[][] consisting of queries of the type {i, val}, the task for… Read More
Given two integers X and Y representing the number of candies allocated to players A and B respectively, where both the players indulge in a… Read More