| 
Given an array of integers and a unique number. find all different combination of numbers
 Microsoft Interview Questions and Answers
 
 (Continued from previous question...) 
62.  Given an array of integers and a unique number. find all different combination of numbers
 
Question:Given an array of integers and a unique number. find all different combination of numbers from the array that add up to the unique number.print all the combination.
 
 
 maybe an answer:
 
 See coin change problem. Dynamic Programming solve the problem in O(n^2)
 
 sort the array.
 for( i=0; j=n ; i<j;)
 {
 sum=arr[i]+[j];
 if(sum<key){i++}
 else if(sum>key){j--}
 if(sum==key)
 print(arr[i],arr[j]);
 
 }
 
 (Continued on next question...) 
Other Interview Questions
 |