I was thinking to use map while storing array? Or if array elements are in some range like < 10^6 or something and you have to tell first occurring index then you can simply make an array of size max(array) and store first index of a number in that… Then on query you can access them in O(1). Or If there is no limit on A_i then unordered map may be more helpful, but depend on your hashing function.
can you explain me how you came up with O(N) mathematical because I am using recurrence relation t(n)=2t(n/2)+O(1) which I think is the relation for the above code