Input: list: [5, 3, 7, 3, 9, 3, 2], find element 3
Goal: Find the first and last index where 3 appears in the list
Step 1: Check element at index 0 (5), not 3
[5, 3, 7, 3, 9, 3, 2]
first = -1, last = -1
Why: We start from the beginning to find the first occurrence
Step 2: Check element at index 1 (3), matches target
[5, 3, 7, 3, 9, 3, 2]
first = 1, last = 1
Why: First time we see 3, record index 1 as first and last
Step 3: Check element at index 2 (7), not 3
[5, 3, 7, 3, 9, 3, 2]
first = 1, last = 1
Why: No change, keep looking
Step 4: Check element at index 3 (3), matches target
[5, 3, 7, 3, 9, 3, 2]
first = 1, last = 3
Why: Update last occurrence to index 3
Step 5: Check element at index 4 (9), not 3
[5, 3, 7, 3, 9, 3, 2]
first = 1, last = 3
Step 6: Check element at index 5 (3), matches target
[5, 3, 7, 3, 9, 3, 2]
first = 1, last = 5
Why: Update last occurrence to index 5
Step 7: Check element at index 6 (2), not 3
[5, 3, 7, 3, 9, 3, 2]
first = 1, last = 5
Why: No change, finished scanning
Result: Final: first occurrence = 1, last occurrence = 5