Posts

Showing posts from 2021

Stock Buy and Sell to earn Maximize Profit programme in Python

Stock Buy and Sell to earn Maximize Profit programme in Python def sell_profit(price,n):          i =  0      while (i<n- 1 ):         """We check if next price is less so we use next price becaue we need minimum           buy amount."""          while (i<(n- 1 )  and  price[i+ 1 ] <= price[i]):             i +=  1          if  i == n- 1 :              break         buy = i          i +=  1                     """we check if previous price is less than our current price so we                 increment price and  again check it previous price                 because we need maximum profit for selling."""          while (i<(n)  and  price[i] >= price[i- 1 ]):             i +=  1         sell = i- 1          print ( "buy on the day :  {}  , sell on the day :  {} "  .  format (buy,sell)) price = [ 50 , 100 , 250 , 300 ,3 0 , 540 , 620 ] n =  len (price) sell_profit(price,n) # Time Complexity O(n) # For m