Concept Flow - First and Last Occurrence of Element
Start
Initialize first = -1, last = -1
Traverse array from i=0 to n-1
Check if array[i
If first == -1, set first = i
Set last = i
Continue traversal
End traversal
Return first and last
We scan the array once, updating first occurrence when we find the target first time, and last occurrence every time we find it.
