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)
Sigiloso
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.