Комментарии:
I did almost the same code in c++, however I check for sea level = 0 after processing each step. If SL==0 and our previous step was UP, we must have been in a valley.
Ответитьwrong solution ... need improvement
ОтветитьHey but if I have [UUUUDDUD] then I won't be able to check -1. I'm confused. Thanks for the video btw.
Ответитьthank you
Ответить2 hours later.... Thank you. Didn't think about the only previous direction to count will be going up to 0 by 1 step so track if value == -1. Thank yoU!
ОтветитьThanks nice solution
ОтветитьI'd do the check of elevation === -1 after I decrease the elevation. The reason for this is that every time the elevation goes down from 0 to -1 it'll count as a valley. If you step with the debugger you'll see that I mean. Either way, it was a great explanation.
ОтветитьI tried this problem using Regex but it only passed some of the test cases
ОтветитьHope I do good in today's job interview. I'm sharing this everywhere man, thanks
ОтветитьVery nicely explained.
Ответить