n = size of num
i = 0
j = n-1
while(i < j) {
   c = num[i] + num[j]
   if(c < given number) i++
   else if(c > given number) j--
   else show<i,j> and  j--
}



2006/4/21, iwgmsft <[EMAIL PROTECTED]>:
>
> one of microsoft interview question....if anybody interested
>
> in given array int num[10]={1,-5,6,7,9,9,20,25,31,45} it is a sorted
> array.
>     write a function void findsum(int [],int x)
> int [] is array and x is number.
> function should print all possible pair of elements in array that can
> make a sum equal to x.
> for example if value of x is 26
> then function should print
>         1,25
>         25,1
>        -5,31
>         31,-5
> Function should be implemented using O(N) or O(2N) approach try to
> avoid using O(N 2) approach(Means avoid nested loop).
>
>
> >
>


--
myblog: http://gnor.net/daizisheng/blog/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to