让reddit/r/programming炸锅的一个帖子,还是挺有意思的

这是原帖

http://www.reddit.com/r/programming/comments/358tnp/five_programming_problems_every_software_engineer/

后来作者被人发现他自己给的solution是错的,然后有人调侃他自己应该通不过自己的面试。

http://www.reddit.com/r/programming/comments/35cr6n/real_programmers_can_do_these_problems_easily/

作者svpino被喷得很惨……一大波被面试题虐过的程序员还在持续赶往途中……

焦点之一是时间限制,如果题目难度全都像前三道题(大概就是:你是否知道这个世界上有编程这件事情,嗯),1个小时绰绰有余,但是对第4题和第5题则不那么确定。毕竟作者说的是“每一个”软件工程师都应该能做到,而很多从业超过20年的前辈纷纷表示他们超时了,而且实际工作中也根本用不上类似的技巧。

anyway,他列出来的第4题和第5题还是有趣的。

Problem 4

Write a function that given a list of non negative integers, arranges them such that they form the largest possible number. For example, given [50, 2, 1, 9], the largest formed number is 95021.


Problem 5

Write a program that outputs all possibilities to put + or - or nothing between the numbers 1, 2, ..., 9 (in this order) such that the result is always 100. For example: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100.

第四题如果数字少,暴力穷举permutation勉强也是个办法,但是如果数字多,如何排序其实没有那么容易想到。

第五题除了暴力穷举,还真想不到什么好办法,而且可能写起来有点烦。

原文地址:https://www.cnblogs.com/kkzxak47/p/4491483.html