Stock Maximize
Stock Maximize
+ 0 comments def stockmax(prices): res = 0 while prices: max_price = max(prices) idx_max = prices.index(max_price) cur_pft = sum([max_price - p for p in prices[:idx_max]]) res += cur_pft prices = prices[idx_max+1:] return res
+ 0 comments If you’d like to experience something a bit more cultural, you can explore the island’s unique blend of African and Indian culture. From exploring the many markets found in the cities to visiting the beautiful temples, you’ll be able to experience the local culture to its fullest. https://nursevalley.com/best-pens-for-nurses/
+ 0 comments I iterate over the prices list in reverse:
long stockmax(vector<int> prices) { long res = 0; long cap = LONG_MIN; for(int i = prices.size() - 1; i >= 0; i--) { cap = max(cap, (long) prices[i]); res = res + cap - prices[i]; } return res; }
+ 0 comments Hey. If you're interested in trading cryptocurrency, one coin you might want to consider buying is Tron. TRX is a promising digital asset with a solid reputation in the crypto world. It's often considered one of the top 20 coins by market cap and has the potential for significant growth. If you're looking for a place to buy Tron, you might want to check out some reputable cryptocurrency exchanges like Switchere.com platform.
+ 0 comments This is my javascript Solution
function stockmax(prices) { let result = 0, arr = [...prices]; arr.sort((a, b) => b - a); let index; for(let i = 0; i < arr.length; i++) { index = prices.indexOf(arr[i]); for(let j = 0; j <= index; j++) result += arr[i] - prices.shift(); if(prices.length === 0) return result; } }
Sort 361 Discussions, By:
Please Login in order to post a comment