Home
Gaurav's GitHub Page
Cancel

Find Number of Divisors

Problem Description Given a number N, find the number of divisors of that number Solution To solve this problem optimally, we will make use of Smallest Prime Factor algorithm covered previously....

Smallest Prime Factor

Problem Description Given N, find the smallest prime factor for all numbers from [2-N] Solution The solution to this problem is similar to how we found out all prime numbers till N using Sieve o...

Find Prime Numbers

Problem Description Given a number N, return a list of all prime numbers till N. Solution This can be optimally solved using Sieve of Eratosthenes algorithm. First we creat an boolean array ...

Check Prime

Problem Description Given a number N check if it’s a prime number. Solution The main this to remember here is that we need to check only till square root of N, because if i is a factor of N, N/i...

A%M == B%M

Problem Description Given two integers A and B, find the greatest possible positive integer M, such that A % M = B % M. Solution This problem needs some derivation: A%M = B%M => A%M - B%M...

Change Array[i] to Array[Array[i]]

Problem Description Given a list of elements (an array) and a postive integer m, replace all elments such that Array[i] = Array[Array[i]]. All elements in the array are in the range [0, N-1]. Sol...

Merge Two Sorted LinkedList

PROBLEM DESCRIPTION Merge two LinkedList which are sorted such that the final LinkedList is also sorted. (Without creating a new LinkedList) SOLUTION This problem is also part of AlgoExpert: htt...

Maximum Sum Sub-Matrix

Problem Description Given a 2D matrix, find the maximum possible sum of sub-matrices in that matrix. Solution The brute force approach is to get all sub-matrices, calculate the sum and update th...

Largest Range in the Array

Problem Description Given an array of integers, return the start and end element (not index) which represents the maximum continuous range of numbers present in the array. Example: 1 11 3 0 15 5 2...

Sort based on Three Numbers

Problem Description You are given an array of 3 integers and another array which contains only the numbers present in the first array. The 3 numbers in the “order” array need not be sorted. You ne...