Searching and Sorting
37 problems to practice.
Find Pivot Index
1. You will be given an Array nums 2. You need to return the first(if there are multiple) pivot in...
Split Array Largest Sum
1. You will be given an Integer array alongwith its length and an integer m 2. You can split the a...
Allocate Minimum Number Of Pages
1.You are given N number of books. 2.Every ith book has Pi number of pages. 3.You have to alloc...
Counting Elements In Two Arrays
1. You are given two unsorted arrays arr1 and arr2 of sizes M and N respectively. 2. For each elem...
Count Possible Triangles
1. You are given an array of positive integers. 2. You have to find the number of triangles that c...
Count The Triplets
1. You are given an array of distinct integers. 2. You have to find the count all the triplets suc...
Count Zeros In A Sorted Matrix
1. You are given a NxN binary matrix A where each row and column of the matrix is sorted in ascendin...
Distinct Absolute Array Elements
1. Return the number of distinct absolute values from a sorted array containing N integers. 2. An...
Facing The Sun
1. Assume your society has high rise buildings. At the time of sunrise you saw the buildings receivi...
Find K Closest Elements
1. Given a sorted array, two integers k and x, find the k closest elements to x in the array. 2....
Find Minimum In Rotated Sorted Array
1. Suppose an array sorted in ascending order is rotated at some pivot unknown to you. EXAMPLE:[0,...
Find Transition Point
1.You are given a sorted array containing only numbers 0 and 1. 2.You have to find the transition...
Guess Number Higher Or Lower
1. You are playing a game with your friend. Your friend picks a number from 1 to N. 2. You have to...
Heaters
1. You are given two arrays that represent positions of houses and heaters on a horizontal line. 2...
Koko Eating Bananas
1. Koko loves to eat bananas. 2. There are N piles of bananas, the i-th pile has piles[i] banana...
Marks Of Pcm
1.You are provided with marks of physics,chemistr and math of N students. 2.You have to sort the...
Punish The Students
1. You are given two arrays rollno and marks where rollno[i] and marks[i] denote the roll number and...
Search In Rotated Sorted Array
1.You are given an array sorted in ascending order but rotated at some pivot unknown to you beforeha...
Union Of Two Sorted Arrays
1.You are given two sorted arrays arr[] and brr[] of size N and M respectively. 2.You have to find...
Search A 2d Matrix
1. Write an efficient algorithm that searches for a value in a m x n matrix. This matrix has the fol...
Search A 2d Matrix - 2
1. Write an efficient algorithm that searches for a target value in an m x n integer matrix. The mat...
Find Pair With Given Difference
1. Given an array arr of size n, you need to write a program to find if there exists a pair of eleme...
Roof Top
1. You are given an array which represents heights of consecutive buildings. 2. You can move from t...
Find Rotation Count
1. Given an ascending sorted rotated array arr of distinct integers of size N. 2. The array is rig...
Maximize Sum Of Arr[i]*i Of An Array
1. Given an array arr of N integers. 2. Your task is to write a program to find the maximum value...
Count Inversions
1. Given an array of integers. Find the Inversion Count in the array. 2. For an array, inversion c...
Find First And Last Postion Of Element In Sorted Array
1. Given an array of integers nums sorted in ascending order, find the starting and ending position...
Max Sum In The Configuration
1. Given an array, you have to find the max sum of i*A[i] where A[i] is the element at index i in th...
Median Of Two Sorted Arrays
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two s...
Find The Smallest Divisor Given A Threshold
1. Given an array of integers nums and an integer threshold, we will choose a positive integer divis...
Chocolate Distribution
1. Given an array A[] of positive integers of size N, where each value represents the number of choc...
Capacity To Ship Packages Within D Days
1. A conveyor belt has packages that must be shipped from one port to another within D days. 2. The...
Count Zeros Xor Pairs
1. Given an array A[] of size N. 2. Find the number of pairs (i, j) such that A[i] XOR A[j] = 0, a...
Find The Element That Appears Once In Sorted Array
Given a sorted array arr[] of size N. Find the element that appears only once in the array. All othe...
First Bad Version
1. You are a product manager and currently leading a team to develop a new product. Unfortunately, t...
Maximum Number Of 1's Row
Given a boolean 2D array, where each row is sorted. Find the row with the maximum number of 1s.
Largest Number
Given a list of non-negative integers nums, arrange them such that they form the largest number....