I read the solution, but I would like to know more how they could get into the solution, like first interactions of the solution. Reading the solution and the tutorial wasn’t clear enough for me hehe. I would like to know like how they thought 💭 about greedy, it is some similar problem ? I really wouldn’t never get to the solution without seeing it.
e
elizarov
06/01/2019, 6:45 PM
The usual approach to think about greedy problems goes like this.
elizarov
06/01/2019, 6:47 PM
First you look at a potential solution. Then you think how it can be improved. So, if somebody gave you a saw and one of the “ups” is lower than “down” then you can flip them and get another solution. Repeating this process you can always get a solution where all ups are higher than all downs.
elizarov
06/01/2019, 6:47 PM
Now it is obvious that “larger” “ups” and “lower” “downs” are better. So you can always take the largest values of arrays as ups and lowest as down.
elizarov
06/01/2019, 6:48 PM
But you don’t know how many of them to take. Here you use a standard approach called “binary search”.