Please help me find the approach to this question and I have also read the article on geeksforgeeks but still I not getting logic
Not getting any approach to solve
this problem can be solved by using 2 pointer approach and maintaining a frequency array/map.
first pointer: start of sub-array
second pointer: end of sub-array
if current sub-array has distinct numbers, you can add more numbers, if it does not have all distinct numbers, then you can remove numbers
time complexity: O(N)
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.