A[0] = 2 -> 0,2 -> 0-0, 2-0 = 2
A[1] = 6 -> 1,3,6 -> 1-1, 3-1, 6 - 1 = 5
A[2] = 2 -> 0,2
A[3] = 6 -> 1,3,6
A[4] = 1 -> 4 -> 4-4 = 0
A[5] = 6 -> 1,3,6 return 5.
you are given the answer in O(n^2) time that use 2 for loops and an if(nums[i] == nums[j]) result = Math.max(result, j - i);
we only care about the largest index of a number in the array.
I store the numbers in a map and update the index as value
iterate through the nums array once and lookup the map.
result = Math.max(result, map.get(nums[i] - i))
This should be O(n) time and O(n) space