#include iostream
#include cstring
#include conio.h
using namespace std;
int main()
{
int n,a[30],temp[30],x;
cin n;
memset(temp,0,sizeof(temp));
for(int i=0;in;i++)
cin a[i];
cin x;
temp[x-a[0]]=1;
for(int i=1;in;i++)
{
if(temp[a[i]]==1)
A very nice explanation at
http://www.rawkam.com/?p=345
On Tue, Sep 14, 2010 at 3:16 PM, soundar soundha...@gmail.com wrote:
#include iostream
#include cstring
#include conio.h
using namespace std;
int main()
{
int n,a[30],temp[30],x;
cin n;
memset(temp,0,sizeof(temp));
use mapint,bool S
when you encounter a particular number check S[x-num] is true, if so return
that pair. else
S[num]=true
On Sat, Sep 11, 2010 at 1:09 PM, topojoy biswas topojoy.bis...@gmail.comwrote:
put all the numbers in a hash table( which demands O(n) space) and then
pick each number in
Hi,
O(n) solution is possible if the array is presorted!
Else i think it is NOT.
1.Have two ptrs (one from first and other to track the array from
last)
2.s=a[left]+a[right]
3.if(ssum) left++;
else if(ssum) right--;
else
print sum found
On Sep 10, 10:19 pm, bittu shashank7andr...@gmail.com