Saturday, August 30, 2014

Interview Questions

  • Given an Array, replace each element in the Array with its Next Element(To its RHS) which is Larger than it. If no such element exists, then no need to replace. 
                i/p: {2,12,8,6,5,1,2,10,3,2}
                o/p:{12,12,10,10,10,2,10,10,3,2}
  • Your algorithms have become so good at predicting the market that you now know what the share price of Wooden Orange Toothpicks Inc. (WOT) will be for the next N days. Each day, you can either buy one share of WOT, sell any number of shares of WOT that you own, or not make any transaction at all. What is the maximum profit you can obtain with an optimum trading strategy?
  • Given a list of integers, your task is to write a program to output an integer-valued list of equal length such that the output element at index 'i' is the product of all input elements except for the input element at 'i'.
                 i/p: {1,2,3}
                o/p:{6,3,2}    

  • Given a sorted array with duplicates and a number, find the range in the form of (startIndex, endIndex) of that number. 

           find_range({0 2 3 3 3 10 10}, 3) should return (2,4).
           find_range({0 2 3 3 3 10 10}, 6) should return (-1,-1).
          The array and the number of duplicates can be large.


  • There is an array of 3-tuple, in the form of (a, 1, 5). The first element in the tuple is the id, the second and third elements are both integers, and the third is always larger than or equal to the second. Assume that the array is sorted based on the second element of the tuple. Write a function that breaks each of the 3-tuple into two 2-tuples like (a, 1) and (a, 5), and sort them according to the integer.  
           E.g. given (a, 1, 5), (b, 2, 4), (c, 7, 8), output (a, 1), (b, 2), (b, 4), (a, 5), (c, 7), (c, 8).


No comments:

Post a Comment