@Amit: Use a hash table. For each integer x[i] in the array, search for k - x[i]. If found, x[i] and k - x[i] are your pair of integers. Otherwise, add x[i] to the hash table and advance the loop. Output "none" if you get to the end of the array without a hit.
Dave On May 20, 6:38 am, amit <[email protected]> wrote: > given an array of integers, and an integer k, find out two elements > from the array whose sum is k in O(n) time. if no such element exists > output none. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
