Given a vector of ints, find the max number, of which the ints keeps rising.
E.g 1 0 2 1 2 0 1 max is 3, as seen at index 1 3 4 we see 0 1 2.
I was trying to find which ones lead to the max. This is harder than what’s asked.
The focus should be the ending index of the max, and the max at this index depends on all before it.
A temp vector is needed to store the max at each index.
At each iteration, we figure out the max at index i based on the max-s before i.
Again, the solution doesn’t track where it starts and the middle ones; it only track the last element index.
Output from test data:
input: 2 1 3
endAt = 2, maxNum = 2
input: 1 0 2 1 2 0 1
endAt = 4, maxNum = 3
Download: http://riowing.net/p/wp/MaxNumRise.cpp