forked from mission-peace/interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
mission-peace edited this page Jul 24, 2014
·
279 revisions
###Arrays###
- Given two numbers in form of array add them - ArrayAddition.java
- Given stock prices for number of days BuySellStockProfit.java
- Buy sell stock once to maximize profit
- Buy sell stocks any number of times to maximum profit
- Given an array of elements check if elements in the array are consecutive or not. - CheckIfArrayElementsAreConsecutive.java
- Given elements in array divide elements into two groups of closest possible sum Conflict with TugOfWar - DivideNumbersInEqualGroupWithClosestSum.java
- Write a function to determine if array contains duplicate elements within k distance from each other - DuplicateWithinkIndices.java
- Given an array and a number k < n, find all elements occurring more than n by k times - FindElementsOccurringNByKTimesTetris.java
- Given a list of gas stations and amount of fuel they have, find a tour which travels all gas stations - GasStationCircle.java
- Given an unordered array of positive integers, create an algorithm that makes sure no group of integers of size bigger than M have the same integers - GroupElementsInSizeM.java
- Given an array find an increasing subsequence of length 3 which has maximum product - IncreasingSubsequnceOfLength3WithMaxProduct.java
- Given an array find maximum circular contiguous sum - KadaneWrapArray.java
- kth largest element in an unsorted array using quick select - KthElementInArray.java
- kth largest element in two sorted array - KthLargestInTwoSortedArray.java
- Print next greater element for every element in array - LargerElementOnRight.java
- Given an array of 0s and 1s find the largest subarray with equal number of 0s and 1s - LargestSubArrayWithEqual0sAnd1s.java
- Longest increasing subsequence in an array with O(logN) speed - LongestIncreasingSubSequenceOlogNMethod.java
- Given an array maximize i - j such that a[i] > a[j] - MaximumIminusJSuchThatAiGTAj.java
- Given an array, find maximum of all subarrays of size k - MaximumOfSubarrayOfSizeK.java
- Given an array of positive and negative numbers, find a subarray which has maximum product - MaxProductSubarray.java
- Given an array of size n, the array contains numbers in range from 0 to k-1 where k is a positive integer and k <= n. Find the maximum repeating number in this array - MaxRepeatingNumber.java
- Given an array and two numbers, find minimum distance between these numbers. There could duplicates of these numbers in array - MinimumDistanceBetweenTwoNumbers.java
- Find minimum length unsorted subarray, sorting which makes entire array sorted - MinimumSortedWhichSortsEntireArray.java
- Given array of 0 and non zero numbers, move all 0s to the end in O(n) time - MoveAllZerosToEnd.java
- Given an array, return a new array which has multiplication of all elements except own index - MultiplyAllFieldsExceptOwnPosition.java
- Given an unsorted array, find total number of triangles formed taking 3 elements of this array - NumberOfTrianglesInUnsortedArray.java
- Given an array with first negative and then positive numbers, position negative and positive numbers alternately - PositiveAndNegativeNumberAlternatively.java
- Given an array arr[] of size n where every element is in range from 0 to n-1. Rearrange the given array so that arr[i] becomes arr[arr[i]] in O(n) time and O(1) space - RearrangeSuchThatArriBecomesArrArri.java
- Given an array with elements in range of 0 to n-1, one number is repeated and one number is missing. Find both the numbers - RepeatingAndMissingNumber.java
- Stable marriage problem - StableMarriageProblem.java
- Given an unsorted array of nonnegative numbers , find a contiguous subarray with given sum - SubarrayWithGivenSum.java
- Given an array, find triplet which sums to a given value - https://github.com/mission-peace/interview/blob/master/src/com/interview/array/TripletInArray.java
- Given a set of n integers, divide the set in two subsets of n/2 sizes each such that the difference of the sum of two subsets is as minimum as possible - Conflict with DivideNumbersInEqualGroupWithClosestSum - TugOfWar.java
- Given an unsorted array convert it into a < b > c < d > e < f > g fashion - ConvertAnArrayIntoDecreaseIncreaseFashion.java
###Binary Search###
- Given an arithmetic progression with one number mission find that missing number - ArithmeticProgressionSearch.java
- Search an element in sorted array - BinarySearch.java
- Search an element in array which is first increasing then decreasing then increasing or other way round - CircularBinarySearch.java
- Given a sorted array find total number of pairs whose difference is k - CountNDistinctPairsWithDifferenceK.java
- Given a sorted array with duplicates, find first occurrence of a given element - FirstOccurrenceOfNumberInSortedArray.java
- Find floor and ceiling of given element in sorted array - FloorAndCeilingSortedArray.java
- Find median of two sorted array of same size - MedianOfTwoSortedArray.java
- Find a missing number in array of consecutive numbers - MissingNumberInConsecutiveNumbers.java
- Find a value of function in which this monotonically increasing function becomes positive - MonotonicallyIncreasingFunctionBecomesPositive.java
- Find number of pairs where x^y > y^x - NumberOfPairWithXPowerYGreaterThanYPowerX.java
- Given an array find an element which is larger than both its neighbors - PeakElement.java
- Given an array which is sorted and rotated find an element - SortedAndRotatedArraySearch.java
- Minimum element in sorted and rotated array
###Bits###
- Add two number in binary representation - AddTwoNumberInBinaryRepresentation.java
- Given an integer and number k, right or left rotate bits in this integer by k - BitRotation.java
- Using byte array for storing information - ByteAsStorage.java
- Count number of set bits in an integer - CountBits.java
- Given a screen in form of byte array with width and start and end points of a horizontal line. Draw this line DrawHorizontalLine.java
- Given an array in which every number occurs 3 times find this one number occurring only once - FindNumberOccurringOnceOtherNumbers3Times.java
- Given two numbers M and N, insert M into N from i to j bits of N - InsertMintoNiTojBits.java
- Given an integer find next higher/lower integer with same number of set bits as original integer - NextHigherAndNextLowerWithSameNumberBits.java
- Given an integer find next power of 2 greater than this integer - NextPowerOf2.java
- Given an array find one/two number occurring odd number of times - NumberOccuringOddTimes.java
- Given two numbers M and N, how many bit flips are required to convert M into N - NumberOfBitsFlipToConvertNToM.java
- Convert a real number(with decimals) into a binary number - RealNumberToBinary.java
- Given an integer reverse bits of this integer - ReverseBits.java
- Given an integer swap its odd bits with even bits at every position - SwapOddEvenBits.java
- Given an integer and two numbers i and j, swap bits at these positions in this integer - SwapTwoBits.java
- Initially there is a number n. Two players start playing a game turn by turn. Each player has to replace the number n written on the board by n-2^k (for some k >= 0 such that 2^k < n) - WinnerWithBeautifulNumber.java
###Dynamic Programming###
- 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 in the given sequence such that the lines are printed neatly. AdjustWordsInLine.java
- Find longest bitonic subsequence in an array. Bitonic subsequence first increases and then decreases - BitonicSequence.java
- Given a long word which is made up of multiple words, split the long word into individual words - BreakMultipleWordsWithNoSpaceIntoSpace.java
- Coin changing problem. Given set of coins and a total t. - CoinChanging.java
- Total solutions possible to form t.
- Minimum numbers of coin needed to form t.
- Given a positive integer N, count all possible distinct binary strings of length N such that there are no consecutive 1′s - CountNumberOfBinaryWithoutConsecutive1s.java
- Count number of trees that can be formed given a preorder sequence - CountNumberOfTreePreorder.java
- Count number of binary search trees formed by an array of size n - CountNumberOfTreesInBST.java
- Given a rod of length n inches and an array of prices that contains prices of all pieces of size smaller than n. Determine the maximum value obtainable by cutting up the rod and selling the pieces - CuttingRod.java
- Given n dice each with m faces, numbered from 1 to m, find the number of ways to get sum X. X is the summation of values on each face when all the dice are thrown - DiceThrowWays.java
- Given two strings of size m, n and set of operations replace (R), insert (I) and delete (D) all at equal cost. Find minimum number of edits (operations) required to convert one string into another - EditDistance.java
- Given number of floors and certain number of eggs, find the floor from which egg will break using minimum number of drops - EggDropping.java
- Given a bag which can only take certain weight W. Given list of items with their weights and price. Stuff these items in the bag such that it maximizes the value of bag - Knapsack01.java
- Given two strings. Find longest common subsequence/substring between the two strings - LongestCommonSubsequence.java
- Given an unsorted array. Find the longest increasing subsequence in this array - LongestIncreasingSubsequence.java
- Given a sequence, find the length of the longest palindromic subsequence in it - LongestPalindromicSubsequence.java
- Given array of matrices, find a sequence which will have minimum multiplication cost - MatrixMultiplicationCost.java
- Given an array of positive numbers, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjacent in the array - MaxSumForNonAdjacentElements.java
- Given set of jobs with start and end interval and profit, how to maximize profit such that jobs in subset do not overlap - MaximizeProfitWithJob.java
- Find the longest chain which can be formed from a given set of pairs.In every pair, the first number is always smaller than the second number.Chain of pair (c, d) can follow another pair (a, b) if b < c - MaximumLengthChainPair.java