Pergunta de entrevista da empresa Bloomberg

how different processes communicate with each other the advantages and disadvantages regarding multithreading vs multiprocessing given an input of integers that represent stock prices, how to get the best buying and selling price (notice you can only sell after you have bought the stock)

Respostas da entrevista

Sigiloso

23 de jan. de 2013

Ah no the above wouldn't work. it is a dp question. You need to have an array (namely compare_prices) that compares the "min so far" and the value in the stock price array. You have to update the min_so_far once you get a new min value, and compare it with the stock prices afterwards. Suppose you have a following stock prices: {4,5,9,2,8,0,3,7}. You will have to update the min_so_far at 4,2, and 0. Then you will have an array compare_prices of {-1,1,5,-1,6,-1,3,7}. And the max_so_far of the compare_prices array is 7, and you go backwards to find the first -1 from there. That'd be your buying price, and the price at the index of max_so_far is the selling price.

1

Sigiloso

29 de nov. de 2014

Obviously this is a problem of max sub array. Firstly turn the stock prices into returns. Than calculate the maximum continuous subarray within the returns. If properly implemented, this will take you O(n) time.

Sigiloso

23 de jan. de 2013

OK so it was not a question about dynamic programming. I think my brain froze to a point I couldn't see it through. Anyway I've been meaning to put up the answer, so here i am. 1. Compare the FIRST element in the array (which contains the historical data of stock prices) with the rest of the elements. 2. Find the index of the *largest* item in the array, say i 3. Find the minimum value between the indices 0 and i. So that min value would be the buying price, and the largest value would be the selling price.