Skip to content

Category Archives: Greedy

Given an array A[] consisting of N integers, the task is to find the minimum difference between the largest and the smallest element in the… Read More
Given a square matrix mat[][] of dimensions N * N, the task is to print the matrix that can be obtained after swapping the laterally… Read More
Given an integer N, the task is to count the triplets (a, b, c) from the first N natural numbers such that a * b… Read More
Given a 2D array knights[][] of size N * 2, with each row of the form { X, Y } representing the coordinates of knights,… Read More
Given an array arr[] of size N, the task is to find the winner of the game when two players play the game optimally as… Read More
Given an array arr[] of size N, the task is to find the smallest indexed array element whose sign needs to be flipped such that… Read More
Given an array arr[] of size N and an integer K (N % K = 0), the task is to split array into subarrays of… Read More
Given an array arr[] of even length N and an integer K, the task is to minimize the count of replacing array elements by an… Read More
Given an array arr[] consisting of N elements, the task is to find the minimum number of increments required to be performed on the given… Read More
Given a string S of length N, the task is to check if a string can be split into two substrings, say A and B… Read More
Given an array arr[] of positive integers of size N, the task is to check if there exists two non-intersecting subarrays in arr[] such that… Read More
Given three integers L, R, and K, the task is to find the maximum sum of K even multiples of 5 from the range [L,… Read More
Given an integer N (N &e; 3), the task is to split all numbers from 1 to N into two subsequences such that the sum… Read More
Given two numeric strings N and K (K ≤ N), where digits of K are in non-decreasing order, the task is to rearrange digits of… Read More
Given two arrays arr1[] and arr2[] of size N, the task is to count the minimum number of swaps of same-indexed elements from both the… Read More