Skip to content

Category Archives: Searching

Given an array, find the largest element in it. Example:   Input : arr[] = {10, 20, 4} Output : 20 Input : arr[] = {20, 10,… 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
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
Given a sorted array arr[] of n elements, write a function to search a given element x in arr[].A simple approach is to do a… 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
A sorted array is rotated at some unknown point, find the minimum element in it. The following solution assumes that all elements are distinct. Examples:  Input:… 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, find all elements in array that appear more than n/k times. For example, if the input arrays is {3,… Read More
Given an array of integers. Find a peak element in it. An array element is a peak if it is NOT smaller than its neighbours.… Read More
We all aware of binary search algorithm. Binary search is easiest difficult algorithm to get it right. I present some interesting problems that I collected on binary… Read More
Given two sorted arrays, a[] and b[], the task is to find the median of these sorted arrays, in O(log n + log m) time… Read More
Given a book of words. Assume you have enough main memory to accommodate all words. design a data structure to find top K maximum occurring… Read More
Given a boolean 2D array, where each row is sorted. Find the row with the maximum number of 1s.  Example:   Input matrix 0 1 1… Read More
Given an array of integers, find all combination of four elements in the array whose sum is equal to a given value X. For example, if… Read More