# Category Archives: Algorithms

## Last element remaining by deleting two largest elements and replacing by their absolute difference if they are unequal

Given an array arr[] of N elements, the task is to perform the following operation: Pick the two largest element from the array and remove… Read More »

## Finding Median of unsorted Array in linear time using C++ STL

Given an unsorted array arr[] having N elements, the task is to find out the median of the array in linear time complexity. Examples: Input:… Read More »

## Reorder an array such that sum of left half is not equal to sum of right half

Given an array arr[] of even length, the task is to check whether is it possible to reorder the array element such that the sum… Read More »

## Average of Cubes of first N natural numbers

Given a positive integer N, the task is to find the average of cubes of first N natural numbers. Examples:   Input: N = 2 Output: 4.5 Explanation: For integer… Read More »

## Greatest odd factor of an even number

Given an even number N, the task is to find the greatest possible odd factor of N. Examples: Input: N = 8642 Output: 4321 Explanation:… Read More »

## Smallest and Largest N-digit number starting and ending with N

Given an integer N, the task is to find the smallest and the largest N-digit numbers which start and ends with digit N. Examples: Input:… Read More »

## Mountain Sequence Pattern

Given a number N , the task is to generate the pyramid sequence pattern which contains N pyramids one after the other as shown in… Read More »

## Find if there is a path between two vertices in an undirected graph

Given an undirected graph with N vertices and E edges and two vertices (U, V) from the graph, the task is to detect if a… Read More »

## Minimum salary hike for each employee such that no employee feels unfair

There are N employees in a company, and each employee has some ratings. The employees are given a hike in their salary based on their… Read More »

## Range queries for alternatively addition and subtraction on given Array

Given an array arr[] of N integers and Q queries where every row consists of two numbers L and R which denotes the range [L,… Read More »

## Minimum flips required to form given binary string where every flip changes all bits to its right as well

Given a string S, the task is to find minimum flips required to convert an initial binary string consisting of only zeroes to S where… Read More »

## Count of pairs in a given range with sum of their product and sum equal to their concatenated number

Given two numbers A and B, the task is to find the count of pairs (X, Y) in range [A, B], such that (X *… Read More »

## Count of substrings of length K with exactly K distinct characters

Given a string str of lowercase alphabets and an integer K, the task is to count all substrings of length K which have exactly K… Read More »

## Count of subarrays of size K with elements having even frequencies

Given an Array arr[] and an integer K, the task is to count subarrays of size K in which every element appears even number of… Read More »

## Longest subarray whose elements can be made equal by maximum K increments

Given an array arr[] of positive integers of size N and a positive integer K, the task is to find the maximum possible length of… Read More »