让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/post

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

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

 

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

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勉强也是个办法,可是若是数字多,如何排序其实没有那么容易想到。orm

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

相关文章
相关标签/搜索