Quote:
As a hash table of huge length would be created , does that much space available in memmory ?
Hash table, you did it again, already not the solution last time.
You are creating something with large cost to simplify another place of low cost, the result is more cost.
Solve this by hand nums = [2,7,11,15], target = 9
Do you need a hash table ?
Solve this by hand nums[]=[50000000,3,2,4,50000000] target=100000000
Do you need a hash table ?
Just checking every pair is in O(n)= n²
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
[Update]
Quote:
First sorting with time complexity less than O(n square) , and then take two variables , which should be acted as index .
These two indexes , one should start form beginning and other from last of the array .
If the sum is greater than the target , last variable should be decremented.
If the sum is less than target, then the first variable should be incremented...
It is basically the solution, try it ans see how it work.