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 and last positions when we find the target.