ttom). Words should appear in this dictionary: WORD.LST (1.66MB). Heuristic solutions that may not always produce a provably optimal rectangle will be accepted: seek a reasonable tradeoff of efficiency and optimality. (Hint: Use a B-Tree)
http://www.itasoftware.com/careers/work-at-ita/hiring-puzzles.h
TO LEARN, hard.
231. Ö±·½Í¼Ê¢Ë®
CODE
232. We have been given a deck of cards and each combination has a rating eg 3 As is higher than 2 As 1K etc. Write an algorithm such that the probability of picking 3 or 5 or 7 cards from the deck results in high rating
DP,дµÝÍƹ«Ê½
233. ÇóÒ»¸öunsortedÊý×éÖÐ×µÄµÈ²îÊýÁУ¨int Êý×飬¿ÉµÝÔö»òÕߵݼõ£©
http://compgeom.cs.uiuc.edu/~jeffe/pubs/pdf/arith.pdf
ÄÑÌâ¡£¡£¡£ÂÔ
Jump Game:
Given an array start from the first element and reach the last by jumping. The jump length can be at most the value at the current position in the array. Optimum result is when u reach the goal in minimum number of jumps.
For ex:
Given array A = {2,3,1,1,4}
possible ways to reach the end (index list)
i) 0,2,3,4 (jump 2 to index 2, then jump 1 to index 3 then 1 to index 4)
ii) 0,1,4 (jump 1 to index 1, then jump 3 to index 4)
Since second solution has only 2 jumps it is the optimum result.
ÒªÇó£ºO(N) time, O(1) space.
ÀàËÆÓÚDP£¿·´¸´update jump N+1²½ºó£¬¼Ç¼µ½´ïµ±Ç°Î»ÖõÄ×îС²½Êý
234.Ò»¸öÊý×飬²»¿¼ÂÇÖظ´Êý×Ö£¬ÕÒ³öÊý×éÖÐÓжàÉÙ¸öcycle¡£cycle£ºÃ¿¸öelementÈ¥ÕÒËû¶ÔÓ¦µÄindex£¬Èç¹ûindexÔÚ½çÄÚ£¬¾Í¼ÌÐøÕÒÕâ¸öindexµÄÖµËù¶ÔÓ¦µÄÏÂÒ»¸öindexÖ±µ½ÕÒµ½Ò»¸öcycle£¬»òÕß³ö½ç¡£
±È·½Ëµ 0£¬2£¬1£¬9£¬10
¶ÔÓÚ0£¬ index 0 ¾ÍÊÇ val 0£¬ ËùÒÔÊÇÒ»¸öcycle
¶ÔÓÚ2£¬ index 2 ÊÇ 1£¬ ÔÚ½çÄÚ£¬¾ÍÕÒ index 1£¬which is 2£¬ËùÒÔÓÖÊÇÒ»¸öcycle
×ܹ²4¸öcycles£º 0¨C>0, 2 -> 1, 9 -> ½çÍ⣬ 10->½çÍâ
ÏÈÒªÇóдÁ˸ö¿ÉÒÔÓÐextra spaceµÄ£¬È»ºóÒªÇóno extra space
No extra spaceÐèÒªÐÞ¸ÄÔÊý×é°É¡£¡£¡£CODE
235. bool isOverlap(int a, int b, int c, int d)²ÎÊýÈ¡Öµ·¶Î§0~6´ú±íÐÇÆÚ¼¸¡£Äܲ»Äܲ»ÓôóÓںźÍСÓÚºÅ
ÓÃÒ»¸öÆ߸öÊýµÄÊý×éÀ´±ê¼Ç¾ÍÐÐÁË°É
236.¸øÒ»¸öÎüµØ̺µÄirobot£¬ºÍÒ»¸ö³¤·½ÐεÄÎÝ×Ó£¬ËÄÃæÓÐǽ£¬ËĸöÖ¸Á
Bool moveForward£¨£©//ÏòÇ°×ßÒ»¸ñ£¬×ß²»Á˵Ļ°·µ»Øfalse
Void Rotate£¨int degree£©//¾ÍÊÇ×ó¹ÕÓÒ¹Õ
Bool isClean£¨£©//µ±Ç°µ¥Ôª¸ñÊÇ·ñ¸É¾»
Void clean£¨£©
°Ñirobot ÈÓÔÚÎÝ×ÓÈÎÒâλÖã¬Ð´´úÂëÈÃirobotÇåÀí·¿¼ä£¬Ã¿Ò»¸ñ¶¼Òª×ß¹ý£¨µ¥Ôª¸ñûÓÐ×ø±ê£©
ÏÈ×ßµ½½ÇÂ䣬ȻºóÀ´»Øɨ¾ÍÐÐÁË
237. Edit Distance
¼û185Ìâ
238. {1£¬5£¬ -5£¬ -8£¬2£¬ -1£¬15 } Òª°Ñ¸ºµÄɨµ½×ó±ß£¬ÕýµÄɨµ½ºó±ß¡£²»Äܸıä˳ÐòµÃµ½{-5 -8 -1 1 5 2 15} Õâ¸öÌâÓÐtime µÍÓÚ n^2 space=O£¨1£©µÄ½â·¨Âð
Ó¦¸ÃûÓÐÕâÑùµÄ½â£¿
239.¸øÒ»¸öͨ³£µÄ±í´ïʽ£¬×ª³Éºó׺±í´ïʽ
CODE
240. Given n arrays, find n number such that sum of their differences is minimum. For e.g. if there are three arrays
A = {4, 10, 15, 20}
B = {1, 13, 29}
C = {5, 14, 28}
find three numbers a, b, c such that |a-b| + |b-c| + |c-a| is minimum. Here the answer is a = 15, b = 13, and c = 14
ͬ224Ìâ
241. reverse double linked list.
CODE
242. [Facebook] Given an array A of positive integers. Convert it to a sorted array with
minimum cost. The only valid operation are:
1) Decrement with cost = 1
2) Delete an element completely from the array with cost = value of element
DP£¬Ð´µÝÍƹ«Ê½£¬Ê¹[0,i]ÖеÄÔªËØÓÐÐò£¬updateʱ£¬¼ÓÈë[0,i+1]£¬ÒªÃ´decrementÒÔÇ°µÄ£¬ÒªÃ´É¾µôi+1
243. ÔÚÒ»¸öƽÃæÉÏÓÐn¸öµã£¬Éè¼ÆËã·¨¿´Äܲ»ÄÜÕÒ³öËĸöµã¹¹³ÉÒ»¸öÕý·½ÐΣ¬·ÖÎöʱ¼ä¸´ÔӶȡ£
TO LEARN
244. Algorithm to find the two numbers whose difference is minimum among the set of numbers.
For example the sequence is 5, 13, 7, 0, 10, 20, 1, 15, 4, 19
The algorithm should return min diff = 20-19 = 1.
Constraint ¨C Time Complexity O(N) & Space is not a constraint [upto O(3N)]
Assumption ¨C Sorting O(nlogn) & comparison of adjacent numbers is already known & is not an option. Try to keep it linear
Ïë²»³öÀ´¡£¡£¡£
245. Given an array of integers (both positive and negative) divide the array
into two parts (sub-arrays) such that the difference between the sum of
elements in each array is minimum
Èç¹ûsubarrayÁ¬ÐøµÄ»°ºÜ¼òµ¥¡£¡£¡£
246. ¸øÒ»¸östring, ±ÈÈç¡°facebook¡±, ¿ÉÒÔ²ð³É¡°face¡±ºÍ¡°book¡±, ¶ÔÈÎÒ»string, ÕÒ³ö×µÄ¿ÉÒÔ²ð·Ö³ÉÆäËûµ¥´ÊµÄ×Ó´®¡£
ÏÈÔÚstringÀïÕÒÊǵ¥´ÊµÄ·¶Î§£¬µÃµ½Ò»×érange,È»ºó½«ÕâЩrange°´ÆðµãÅÅÐò£¬Ôٵݹé+