[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.
Interview Questions and Answers :: Samsung

14. In an array, how will you find the elements whose sum is "S". Tell all the steps you will do.

Answer:

1) Sort the array in ascending order.

2) Initialize two index variables to find the 'S'

   elements in the sorted array.

       (a) Initialize first to the leftmost index: l = 0

       (b) Initialize second  the rightmost index:  r = ar_size-1

3) Loop while l < r.

       (a) If (A[l] A[r] == S)  then return 1

       (b) Else if( A[l] A[r] <  sum )  then l

       (c) Else r--    

4) No 'S' in whole array - return 0

Post Your Answer Here:      Public      Private

Rate This: +0 -0
Report     

Post Your Reply Here:     

Report Error

Report Error

Please Login First Click Here