Logger Rate Limiter Solution (LeetCode)

This question is from the LeetCode Challenge (Aug-2020). See the original question here Design a logger system that receive a stream of messages along with […]

Fitting Shelves Problem

Given the length of a wall w and infinite shelves of two lengths small and large (large > small). Find the optimal solution to put […]

Assign Mice to Holes

There are N Mice and N holes placed in a straight line. Each hole can accommodate only 1 mouse. A mouse can stay at his […]

Greedy Algorithm for Egyptian Fraction

In early Egypt, people used to use only unit fraction (in the form of (1/n)) to represent the decimal numbers. The fraction was always written […]

Greedy Solution to Activity Selection Problem.

Given n activities with their start and finish times. Select the maximum number of activities that can be performed by a single person, assuming that […]

Job Sequencing with given deadline

Given n Jobs, with their deadline (between 1 to n) and associated profit. Each job takes unit time to complete and you will get the […]

Max Distance between two occurrences of the same element

Given an array of integers where elements may be repeating in the array. Find the maximum distance between two occurrences of the same element in […]

Swapping two variables without using third variable

This is a very common interview question, esp. at the junior level. Let us first write a function that swap two integers using a third […]

Count max points on a line

Given n points on a 2D plane with (x, y) co-ordinates. Find the maximum number of points lie on the same straight line.

Print all Subsequences of an Array

Given an array of integers, Print all possible subsequences of that array.