Order of indices which is lexicographically smallest and sum of elements is <= X

Given an array arr[] and an integer X, the task is to find the indices such that: The sum of elements on the found indices… Read More »

Count common elements in two arrays containing multiples of N and M

Given two arrays such that the first array contains multiples of an integer n which are less than or equal to k and similarly, the… Read More »

Find if a binary matrix exists with given row and column sums

Given an array Row[] of size R where Row[i] is the sum of elements of the ith row and another array Column[] of size C… Read More »

Create a Sorted Array Using Binary Search

Given an array, the task is to create a new sorted array in ascending order from the elements of the given array. Examples: Input :… Read More »

Length of longest sub-array with maximum arithmetic mean.

Given an array of n-elements find the longest sub-array with the greatest arithmetic mean. The length of the sub-array must be greater than 1 and… Read More »

Check whether a subsequence exists with sum equal to k if arr[i]> 2*arr[i-1]

Given a sorted array of positive integers where arr[i] > 2*arr[i-1], check whether a sub sequence exists whose sum is equal to k. Examples: Input… Read More »

Check whether we can sort two arrays by swapping A[i] and B[i]

Given two arrays, we have to check whether we can sort two arrays in strictly ascending order by swapping A[i] and B[i]. Examples: Input :… Read More »

Find the largest possible k-multiple set

Given an array containing distinct positive integers and an integer k. The task is to find the largest possible k-multiple set from the array of… Read More »

Convert given integer X to the form 2^N – 1

Given an integer x. The task is to convert x to the form 2n – 1 by performing the following operations in specified order on… Read More »

Maximum distance between two unequal elements

Given an array arr[], the task is to find the maximum distance between two unequal elements of the given array. Examples: Input: arr[] = {3,… Read More »

Find the lexicographical next balanced bracket sequence

Given a balanced bracket sequence as a string str containing character ‘(‘ or ‘)’, the task is to find the next lexicographical order balanced sequence… Read More »

Maximum possible sub-array sum after at most X swaps

Given an array arr[] of N integers and an integer X, the task is to find the maximum possible sub-array sum after applying at most… Read More »

Greedy approach vs Dynamic programming

A Greedy algorithm is an algorithmic paradigm that builds up a solution piece by piece, always choosing the next piece that offers the most obvious… Read More »

Minimum number of pairs required to make two strings same

Given two strings s1 and s2 of same length, the task is to count the minimum number of pairs of characters (c1, c2) such that… Read More »

Find the largest interval that contains exactly one of the given N integers.

Given an array arr[] of N distinct integers, the task is to find the maximum elements in an interval [L, R] such that the interval… Read More »