sunny

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.
Not written any code for it. Just tried some examples with pen and paper. Here is the solution.
- sunny March 31, 20151. Consider an array. origArr={1,10,15,7,19,4,0}
2. Create a new array. newArr={}
3. Get first element from origArr. Insert it into newArr. So newArr={1}.
4. Get second element from origArr. Is it greater than element in newArr. (is 10 > 1). Insert it into newArr. So newArr = {1,10}. This a sorted Array. maxSum = 10-1 = 9
5. Get next element from origArr(15). Is 15 > last element of newArr (15>10).
6. If so simply replace this last element with this number. So newArr = {1,15}. maxSum = 15-1=14
7. Get next element of origArr(7). Is 7 > last element of newArr? No, so Discard 7.
8. Get next element of origArr(19). Is 19 > lastelement of newArr. Yes. So as before replace last element of newArr with 19. So newArr = {1,19} and maxSum = 19-1 = 18.
9. Get next element of orgiArr(4). Is 4 > last element of newArr. No. Discard 4.
10. Get next element of origArr(0). Is 0 > last element of newArr. No.
11. For all the comparisons where origArr[element] < newArr[lastElement] next step should be executed. (For simplicity i did not mention it in previous steps as it would have made the logic difficult to understand).
12. Is 0 < first element of newArr (1). Yes, so clear the newArr and add this element. So newArr = {0}.
13. Go to step 3 and continue the process to get maxSum.
I have tried it in 2-3 scenarios(again on paper) and logic holds good. Not sure about the complexity of the solution though. Please do comment on any flaws or problems you find in the solution provided.