Skip to content
Mission Peace edited this page Nov 5, 2016 · 12 revisions
  1. Given two numbers in form of array add them - ArrayAddition.java
  2. 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
  1. Given an array of elements check if elements in the array are consecutive or not. - CheckIfArrayElementsAreConsecutive.java
  2. Write a function to determine if array contains duplicate elements within k distance from each other - DuplicateWithinkIndices.java
  3. Given an array and a number k < n, find all elements occurring more than n by k times - FindElementsOccurringNByKTimesTetris.java
  4. Given a list of gas stations and amount of fuel they have, find a tour which travels all gas stations - GasStationCircle.java
  5. 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
  6. Given an array find an increasing subsequence of length 3 which has maximum product - IncreasingSubsequnceOfLength3WithMaxProduct.java
  7. Given an array find maximum circular contiguous sum - KadaneWrapArray.java
  8. kth largest element in an unsorted array using quick select - KthElementInArray.java
  9. kth largest element in two sorted array - KthLargestInTwoSortedArray.java
  10. Print next greater element for every element in array - LargerElementOnRight.java
  11. Given an array of 0s and 1s find the largest subarray with equal number of 0s and 1s - LargestSubArrayWithEqual0sAnd1s.java
  12. Longest increasing subsequence in an array with O(NlogN) time complexity - LongestIncreasingSubSequenceOlogNMethod.java
  13. Given an array maximize i - j such that a[i] > a[j] - MaximumIminusJSuchThatAiGTAj.java
  14. Given an array, find maximum of all subarrays of size k - MaximumOfSubarrayOfSizeK.java
  15. Given an array of positive and negative numbers, find a subarray which has maximum product - MaxProductSubarray.java maxproductsubarray.py
  16. 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
  17. Given an array and two numbers, find minimum distance between these numbers. There could duplicates of these numbers in array - MinimumDistanceBetweenTwoNumbers.java
  18. Find minimum length unsorted subarray, sorting which makes entire array sorted - MinimumSortedWhichSortsEntireArray.java
  19. Given array of 0 and non zero numbers, move all 0s to the end in O(n) time - MoveAllZerosToEnd.java
  20. Given an array, return a new array which has multiplication of all elements except own index - MultiplyAllFieldsExceptOwnPosition.java
  21. Given an unsorted array, find total number of triangles formed taking 3 elements of this array - NumberOfTrianglesInUnsortedArray.java numberoftrianglesunsortedarray.py
  22. Given an array with first negative and then positive numbers, position negative and positive numbers alternately - PositiveAndNegativeNumberAlternatively.java
  23. 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
  24. 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
  25. Stable marriage problem - StableMarriageProblem.java
  26. Given an unsorted array of nonnegative numbers , find a contiguous subarray with given sum - SubarrayWithGivenSum.java
  27. 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
  28. 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 - TugOfWar.java
  29. Given an unsorted array convert it into a < b > c < d > e < f > g fashion - ConvertAnArrayIntoDecreaseIncreaseFashion.java
  30. Given multiple sorted lists, sort them into one list - ChunkMerge.java
  31. Given an array which represents bars how much rain water will be trapped - TrappingWater.java
  32. Print nth number of count sequence. Sequence is like 1 11 21 1211 111221 and so on. NthElementOfCountNumberSequence.java
  33. Given 2 arrays of same length consisting of 0s and 1s find max span i,j in two arrays such that sum b/w i to j is same. LongestSameSumSpan.java longestsamesumspan.py
  34. Count number of inversions where i < j < k and input[i] > input[j] > input[k] in array. CountInversionOfSize3.java countinversionofsize3.py
  35. Given an array of unique integers and total, find all triplets whose sum is less than total. TripletSumLessThanTotal.java tripletsumlessthantotal.py
  36. Given array of 0s and 1s and maximum flip allowed from 0 to 1, find maximum number of consecutive 1s you can have in array. Flip0sMaximum1s.java flip0smaximum1s.py
  37. Given two arrays, arrange elements of first element by values in second array. ReorderArrayByIndex.java reorderarraybyindex.py
  38. Given an array find which rotation will give max sum of i*arr[i] - RotationWithMaxSum.java rotationwithmaxsum.py
  39. Zig zag arrangement of array. ZigZagArrangement.java zigzagarrangement.py
  40. Rearrange array with elements in range 0 to n-1 such that arr[i] = j becomes arr[j] = i. RearrangeArrayPerIndex.java rearrangearrayperindex.py
  41. Given sorted array of positive integers find smallest positive integer not represented by sum of some subset of this array. SmallestIntegerNotRepresentedBySubsetSum.java smallestintegernotrepresentedbysubsetsum.py
  42. Arrange positive and negative numbers alternatively maintaining order in input array. PositiveAndNegativeNumberAlternativelyMaintainingOrder.java positiveandnegativealternativelymaintainingorder.py
  43. Given two sorted arrays find max sum path from start of any array to end of any array. Switch only happens at common array element. MaximumSumPathTwoArrays.java maximumsumpathtwoarrays.py
  44. Find common elements in 3 sorted array. CommonThreeSortedArray.java commonthreesortedarray.py
  45. Generate minimum number from give sequence of D and I where D indicates decrease and I indicates increase.[MinimumNumberFromSequence.java] (https://github.com/mission-peace/interview/blob/master/src/com/interview/array/MinimumNumberFromSequence.java)
  46. Count smaller numbers on right side of every element in given array - CountSmallerOnRight.java
  47. Find max array created by picking k elements from array1 and array2 by maintaining order in both the arrays - MaxNumberFromTwoArray
  48. Find duplicate in array of size n + 1 with elements from 1 to n in O(1) space - DuplicateNumberDetection.java
  49. Shortest palindrome from a string - ShortestPalindrome.java
  50. Find if there exists an increasing subsequence of length 3 or increasing triplet -IncreasingTripletSubsequence.java
  51. Given an unsorted array find maximum gap between consecutive element in sorted array - MaximumGap.java
  52. Find longest consecutive subsequence in an unsorted array - LongestConsecutiveSubsequence.java
  53. Wiggle sort - WiggleSort.java
  54. Best meeting point from bunch of people - BestMeetingPoint.java
  55. Given an array of positive number arrange it in max min fashion - MaximumMinimumArrangement.java
  56. Given a string find if it can form additive number - AdditiveNumber.java
  57. Minimum number of meeting rooms needed to schedule array of meetings - MeetingRooms.java
  58. Four sum in array equal to given target - FourSum.java
  59. Determine if you can reach end of array. You can jump as much as value at every position of array - JumpGame.java
  60. Given a sorted array of integers nums and integer values a, b and c. Apply a function of the form f(x) = ax2 + bx + c to each element x in the array - SortedArrayTransformation.java
  61. Find missing ranges in sorted array - MissingRanges.java
  62. Given a sorted integer array without duplicates, return the summary of its ranges - SummaryRanges.java
Clone this wiki locally