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
-
STL Benifits: 1.Code Reuse 2.Efficiancy and Fast 3.Accurate and less buggy 4.Simple code and readable 5.Standardized and helps in writ...
-
Given n numbers, find out i and j where 1<=i<=j<=n, where the sumof elements from i to j is maximum. All positive : Sum of all ele...
-
Breadth First Algorithm OR Level wise printing of a BST: /* Breadth first traversal using queue */ void BreadthFirstTraversal(Tree *root)...
No comments:
Post a Comment