注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
分享下前段时间 Squarepoint Capital的面试。
寒暄了下,开始介绍自己从哪来的,research干什么。。。以下是面试题目:
统计:
Coding:
第一题:蠡口121,
第二题:Let an array of nonnegative numbers represent the height of woodbars. Compute the units of water that are stuck between the woodbars. For examples:
- [4, 1, 3, 1, 0, 2] return 5.
- [9, 1, 9] return 8.
- [2, 5, 10, 3, 4, 6, 9, 2, 6] return 18.
因为自己刷题太少,第二题全程懵逼。在小哥的提示下,结束时还是没做出来,面到最后心态都崩了。。。面试结束才想到下面的并不是很efficient解决方案。
求问下论坛里的大佬有没更好的方法?这个是不是很leetcode的题?然后收到了拒信,感觉面quant的职位不把leetcode中median 和easy的刷完,就是在浪费自己的机会。。。
- def water_level_at_i_th(i, woodbars):
- n = len(woodbars)
- if i == 0 or i == n - 1:
- return 0
- else:
- return max(0, min(max(woodbars[0:i]) - woodbars[i], \
- max(woodbars[(i + 1):]) - woodbars[i]))
- def water_levels(woodbars):
- res = 0
- for i in range(len(woodbars)):
- res += water_level_at_i_th(i, woodbars)
- return res
- if __name__ == '__main__':
- woodbars = [2, 5, 10, 3, 4, 6, 9, 2, 6]
- print(water_levels(woodbars))
复制代码
|