Index = n if not found

Why is index = n if element is not found?

If the element is not found, the iterator will point to a position just after the last valid index. It just acts as an indicator.
So by checking the iterator, you can know whether the element is present or not.

@shivanshu.khajuria Please mark your doubt as resolved if it is so.