Problem Description Given two integer arrays, A and B of size N and M, respectively. Your task is to find all the common elements in both the array. Each element in the result should appear as man...
Count Rectangles
Problem Description Given two arrays of integers A and B of size N each, where each pair (A[i], B[i]) for 0 <= i < N represents a unique point (x, y) in a 2-D Cartesian plane. Find and retu...
Count Right Triangles
Problem Description Given two arrays of integers A and B of size N each, where each pair (A[i], B[i]) for 0 <= i < N represents a unique point (x, y) in 2D Cartesian plane. Find and return ...
Minimum Area Rectangle
Problem Description We are given an array of [x,y] co-ordinates. Write a function which returns the minimum area of any rectangle that can be formed using any 4 points in this array. The sides of ...
Count of Pairs with k Sum in Sorted Array
Problem Description Given a sorted array of distinct integers A and an integer B, find and return how many pair of integers ( A[i], A[j] ) such that i != j have sum equal to B. Solution public c...
Sub-Array with Given Sum (Two Pointers)
Problem Description Given an array of positive integers A and an integer B, find and return first continuous subarray which adds to B. (First sub-array means the sub-array for which starting index...
Maximum Water between Two Walls
Problem Description Given an array of size N, where A[i] represents the height of the ith wall, pick any two walls such that maximum water can be stored between them. Solution We start from the ...
2 Pair Difference (Two Pointers)
Problem Description Given N distinct sorted elements, check if there exists a pair (i,j) such that A[i] - A[j] = k and k>0. (i!=j) Solution Two important thing in question is to figure out wh...
2 Pair Sum (Two Pointers)
Problem Description Given N distinct sorted elements, check if there exists a pair (i,j) such that A[i] + A[j] = k, i!=j. Solution The brute force approch is to check all pairs - O(N^2) A better...
Kth Element (Without Sorting)
Problem Description Given unsorted array of N distinct elements, find kth index position of its sorted form. (k will start from 0) Note: We cannot modify the array and we cannot use extra space. ...