讓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

相關文章
相關標籤/搜索