Given : An unsorted array A of integers

Input : An integer k

A = {3,4,5,1,4,2}

Input : 6

Output : {5,1}, {4,2}

How can I do this in O(n) or O(log n). Any suggestions will be appreciated.

Printable View

- 12-04-2011, 05:18 AMjamalraihanFind two elements in an array that sum to k
Given : An unsorted array A of integers

Input : An integer k

A = {3,4,5,1,4,2}

Input : 6

Output : {5,1}, {4,2}

How can I do this in O(n) or O(log n). Any suggestions will be appreciated. - 12-04-2011, 05:34 AMpbrockway2Re: Find two elements in an array that sum to k
Can you find any or all such pairs at all? But what algorithm and how many operations does it take?

O(log n) would be a neat trick. What do you mean by the expression "O(log n)"?