Home
Gaurav's GitHub Page
Cancel

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. ...

Special Integer - Maximum Sum with Max Length k

Problem Description Given an array of +ve integers, find maximum k such that: {max subarray sum of length k <= B}, where B is a given input +ve integer. Solution We have given a number B and ...

Ath Magical Number

Problem Description Given A, B and C, find Ath magical number. Note: A number is said to be magical, if it’s divisible by B or C. Solution package com.gauk; public class MagicNumberModded { ...