void StockProcess(const vector<int>& stocks, int* buyday, int* sellday) { int min_index = 0; *buyday = 0; *sellday = 0; for (int i = 1; i < stocks.size(); ++i) { if (stocks[i] < stocks[min_index]) { min_index = i; } else if ( (stocks[i] - stocks[min_index]) > (stocks[*sellday] - stocks[*buyday])) { *buyday = min_index; *sellday = i; } } }
Wednesday, 21 March 2012
Puzzle : Find the best time to buy and sell a stock from a list of values in an array
Subscribe to:
Post Comments (Atom)
AWS Data Pipeline Services
https://www.youtube.com/watch?v=tykcCf-Zz1M
-
While considering using/building a cache for your systems, you need to consider Use of Cahce - Cache is mainly used to reduce the latency ...
-
Follow this order for design interview prep: Connect to Arslan Ahmad on linked in, lot of good quick cheet sheets you get from Arslan on s...
No comments:
Post a Comment