Skip to content

Category Archives: Algorithms

You are given a set of n types of rectangular 3-D boxes, where the i^th box has height h(i), width w(i) and depth d(i) (all… 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
You are given a function foo() that represents a biased coin. When foo() is called, it returns 0 with 60% probability, and 1 with 40%… Read More
We have discussed Dynamic Programming solution for Longest Increasing Subsequence problem in this post and a O(nLogn) solution in this post. Following are commonly asked… Read More
Given a number, find the next smallest palindrome larger than this number. For example, if the input number is “2 3 5 4 5”, the… Read More
  Given an array of n elements, where each element is at most k away from its target position, devise an algorithm that sorts in… Read More
Given an array of integers, find anyone combination of four elements in the array whose sum is equal to a given value X. For example, … 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
Given two signed integers, write a function that returns true if the signs of given integers are different, otherwise false. For example, the function should… Read More
You are given n pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can… Read More
Given a sequence of words, and a limit on the number of characters that can be put in one line (line width). Put line breaks… Read More
Given a function foo() that returns integers from 1 to 5 with equal probability, write a function that returns integers from 1 to 7 with… Read More
Deterministic Finite Automaton (DFA) can be used to check whether a number “num” is divisible by “k” or not. If the number is not divisible,… Read More
Write a function that calculates the day of the week for any particular date in the past or future. A typical application is to calculate… Read More
  Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number.  Example: … Read More