The reason for taking -1 is that it should not conflict with any other number in array. If you take any other number and if that number is present in array the output will be wrong so if it is integer array any negative value or value that is not going to be present in array will work
you are the life saviour, no one in the youtube gives this explanation, thank you.
Hi.. Space complexity is an issue here, if you use multiple loops approach
Finally Im cool with This explanation
finally understood thank you
thanks mam..understood finally
can we put some other value instead of -1 in (int visited) please tell if possible
The reason for taking -1 is that it should not conflict with any other number in array. If you take any other number and if that number is present in array the output will be wrong so if it is integer array any negative value or value that is not going to be present in array will work
@@CodeBode so we can take -2 also?
Yes
How to do this same program using inheritance
@@shivam7164 The idea to take any marker. The value that you know won't occur in array. It can be -10, it can be 100. Etc.
super explained thank you
Getting error with this code...with ArrayIndexoutOfBounds...
it usually happens when you access element greater than array length(keep in mind array indexing starts from 0 to n-1)
best of all ty.
Understood. Thanks.
Awesome
Madam element tesukoni explain cheyochuga madam ex array [I] = 2 then process going like that
how to solve this que with 0(n)
Use hashmaps
Life saver
thank you
Why are u using new array?
❤️❤️
This is not efficient method as it's gets O(n^2)time complexity
True this is not the most efficient just one of the way to find the frequency. Thanks for the comment. Keep learning!
@@CodeBode mam please do the same program with any other method
Not the most efficient way but I don't see your example posted.
copy paste from Javatpoint :p :p