Skip to content

Category Archives: Searching

Given two arrays A1[] and A2[], sort A1 in such a way that the relative order among the elements will be same as those are… Read More
The most common method to calculate mid or middle element index in Binary Search Algorithm is to find the middle of the highest index and… Read More
Given a sorted array arr[] of size N, some elements of array are moved to either of the adjacent positions, i.e., arr[i] may be present… Read More
Given a sorted array arr[] and a value X, find the k closest elements to X in arr[].  Examples:  Input: K = 4, X =… Read More
Linear Search is defined as a sequential search algorithm that starts at one end and goes through each element of a list until the desired… Read More
Given an array arr[] of size N, the task is to find the largest element in the given array.  Examples:  Input: arr[] = {10, 20,… Read More
Given an n x n matrix, where every row and column is sorted in non-decreasing order. Find the kth smallest element in the given 2D… Read More
Given an array of 1s and 0s which has all 1s first followed by all 0s. Find the number of 0s. Count the number of… Read More
Binary Search is defined as a searching algorithm used in a sorted array by repeatedly dividing the search interval in half. The idea of binary… Read More
We basically ignore half of the elements just after one comparison. Compare x with the middle element. If x matches with middle element, we return… Read More
Morgan Stanley interview experience 1st round: (90 minutes) It was multiple choice questions round. It consists of 3 sections: 1. This section had computer fundamental… Read More
Given a sorted array arr[] (may be distinct or may contain duplicates) of size N that is rotated at some unknown point, the task is… Read More
Given a function ‘int f(unsigned int x)’ which takes a non-negative integer ‘x’ as input and returns an integer as output. The function is monotonically… Read More
Given an array of size n and an integer k, find all elements in the array that appear more than n/k times.  Examples: Input: arr[]… Read More