is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
Since the sum has to be minimum, implies
- Sunny November 28, 20131) both the numbers are supposed to in ascending order
2) length of both the numbers should be half the length of array.
3) The minimum number in the array has to be the as the starting(first) number of either of the two numbers to be found.
assume 1,2,7,8,9 - then 1 has to be first number in either of the two numbers to be found (127).
Steps
a) sort the array in ascending order.
b) Take the first element of the array (minimum in the array) as the starting of either of the numbers to be found.
c) Now first element of a number to be found is fixed. Have a global variable min initialized to a high value.
d) As in the example you have to choose numbers among 2,7,8,9 and in (b) we chose 1 as a part of a number to be found.
e) Now as for the (2) point one number will be of length 3, another will be of length 2.
f) Get 2 numbers from the array left 2,7,8,9 to be grouped with 1 (already choosen). for instance 27 89, remember both the numbers here should be in ascending order (1). No of ways to choose two numbers here are 6 [4!/(2!*2!)].
g) Now we can have 127 and 89 or 189 or 27 sum and compare both, next 28 is chosen another will be 79 again do sum and comparision, In short this logic is exactly same as Subset sum problem (Dynamic Programming) logic, with a slight modification. Using recursion you can find the two numbers from the array 2,7,8,9 associate each of them with 1 and check whether it's minimum.
h) For handling zeros in the array, after the sort neglect all the zeros and start the work with the fresh array with no zeros.
2,7,8,9
27,89 => 127,89 or 27,189
28,79 => 128,79 or 179,28
29,78 => 129,78 or 178,29
Hence the six combinations.