Skip to content

Category Archives: Searching

Given an unsorted of distinct integers, find the largest pair sum in it. For example, the largest pair sum in {12, 34, 10, 6, 40}… Read More
Given an array arr[] of distinct elements size N that is sorted and then rotated around an unknown point, the task is to check if… Read More
Suppose you have a sorted array of infinite numbers, how would you search an element in the array?Source: Amazon Interview Experience. Since array is sorted, the… Read More
Given an array that represents elements of arithmetic progression in order. One element is missing in the progression, find the missing number.  Examples:  Input: arr[]… Read More
The following is a simple recursive Binary Search function in C++ taken from here.  C++ // CPP program for the above approach #include <bits/stdc++.h> using… Read More
We recommend reading the following posts as a prerequisite for this post.K’th Smallest/Largest Element in Unsorted Array K’th Smallest/Largest Element in Unsorted Array | Expected Linear… Read More
Prerequisite: K’th Smallest/Largest Element in Unsorted Array | Set 1 Given an array and a number k where k is smaller than the size of… Read More
Given an array and a number k where k is smaller than the size of the array, we need to find the k’th largest element… Read More
C++ #include <iostream> using namespace std;   int main() {       cout << "GFG!";     return 0; } Output GFG! Given an array and a number… Read More
Given two sets represented by two arrays, how to check if the given two sets are disjoint or not? It may be assumed that the… Read More
Given two sorted arrays and a number x, find the pair whose sum is closest to x and the pair has an element from each… Read More
Given a sorted array and a number x, find a pair in an array whose sum is closest to x. Examples: Input: arr[] = {10,… Read More
Given a binary array arr[] of size N, which is sorted in non-increasing order, count the number of 1’s in it.  Examples:  Input: arr[] =… Read More
Given three arrays sorted in non-decreasing order, print all common elements in these arrays. Examples:  Input: ar1[] = {1, 5, 10, 20, 40, 80} ar2[] = {6,… Read More
Given an array of integers arr[], The task is to find the index of first repeating element in it i.e. the element that occurs more… Read More