Using LinkedHashMap for Solving this Java

I used a LinkedHashMap Approach for this question. Is using Maps for solving questions a good approach or not since the complexity of this is also O(n). In FAANG interviews can it play a wrong impression If I solve questions very easily using hashMap or LinkedHashMap. ??

hello @atul51

In interviews its ok to first present an easy / brute force approach.
later interviewer might tell u to optimise it furthur so that time u need to improve it.

Its a good idea to first propose an easy solution and gradually move to more efficcient solution . this way u can show ur thought process like how u arrived to effcient solution.

Hi @aman212yadav

my doubt over here is if Map uses O(n) times complexity and the suggested algorithm also uses O(n) times. Is there any other specific reason why a linkedHashmap should be avoided as it is very simple and convenient to use.

its not avoided, its too easy to come up , thats why they have added one constraint i.e u need to do it in O(1) space.

this map solution is not space effcient , it is taking O(N) space ,but u need to solve it in O(1) space .

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Hi @aman212yadav

you have cleared my doubts thanks for the quick support.