I am referring to the following question that was asked before. And, I am interested in the following solution mentioned over there:
I am trying to understand it for the following integer array and I am lost after iteration #5 as shown below :
Let's say our integer array is : {1,2,3,4,8,9,10} and we should print those pairs for which sum is equal to 12. So, I tried to analyze step by step what happens if we apply the above mentioned approach:
Key Value
Iteration 1 : i = 0 (12-1) = 11 1
Iteration 2 : i = 1 (12-2) = 10 2
Iteration 3 : i = 2 (12-3) = 09 3
Iteration 4 : i = 3 (12-4) = 08 4
Iteration 5 : i = 4 // pairs.containsKey is true here so printing
input[i] = 8
Could any one explain me why are we printing input[i] = 08 and pairs.get(input[i])) which is also 08 in iteration #5 above?
Secondly I didn't find anything online as far as codaddict's algorithm is concerned.