Best Time to Buy and sell Stock 系列

经典面试题

Edit on 9月20日。上周五的Bloomberg on campus interview 考了这题,但是是可以买入多笔Transactions 不是only one. 所以基本上算是Best Time to Buy and Sell Stock II 那题

Best Time to Buy and sell Stock 系列_第1张图片

這題每次回顧答案的時候都覺得很簡單,過一段時間再看又不會。

Best Time to Buy and sell Stock 系列_第2张图片

Best Time to But II:

.....

妈的   为什么我在校招面试的时候那么傻逼。。。。。。。。想了一会

这个当然是有利润就拿下来别想太多啊! 我因为以前只专门看过stock I 的题,所以一直把思路限制在那里。。。

【不对。。。看完答案这个题还是很难的】

Best Time to Buy and sell Stock 系列_第3张图片

没想到还是错的。。。发现了一个好变态的Edge case。。。

4 6 8 2 的情况。 应该4 买 8卖 赚 4的。 但是如果4 买 6 卖 只能赚2.

Best Time to Buy and sell Stock 系列_第4张图片



Best Time to Buy and sell Stock 系列_第5张图片

这个Idea 太牛啦!

完全模拟了股票市场该怎么玩! 我们一定是低谷买进抄底,然后等到上涨到波峰的时候卖掉。

有一点不同的是 波峰是一个local 波峰而不是全局波峰。如果是全局波峰我们只能赚一笔。。

Best Time to Buy and sell Stock 系列_第6张图片
Best Time to Buy and sell Stock 系列_第7张图片
Best Time to Buy and sell Stock 系列_第8张图片


Best Time to Buy and Sell Stock III


Best Time to Buy and sell Stock 系列_第9张图片

最多 两笔transactions! 

这题看起来跟Part1 很像 但是难度上涨很多!是一个Hard的DP题。


Best Time to Buy and sell Stock 系列_第10张图片


Best Time to Buy and sell Stock 系列_第11张图片


Best Time to Buy and Sell Stock IV【也是一题hard】


Best Time to Buy and sell Stock 系列_第12张图片

哇,这个是一个general version of 上一题。。尼玛更难。

区间Interval!!!!

Best Time to Buy and sell Stock 系列_第13张图片

Best Time to Buy and Sell Stock with cool down:


Best Time to Buy and sell Stock 系列_第14张图片

你可能感兴趣的:(Best Time to Buy and sell Stock 系列)