Report Where a Value Appears
Company: Upstart
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Take-home Project
# Report Where a Value Appears
Given a target and an even-length integer list, return four binary flags describing whether the target occurs:
1. at an even zero-based index;
2. at an odd zero-based index;
3. in the first half of the list;
4. in the second half of the list.
### Function Signature
```python
def occurrence_flags(target: int, values: list[int]) -> list[int]:
...
```
### Example
```text
Input: target = 7, values = [7, 2, 3, 7, 5, 6]
Output: [1, 1, 1, 1]
```
### Constraints
- `0 <= len(values) <= 1_000_000`
- `len(values)` is even.
- Values and `target` are signed 64-bit integers.
### Clarifications
- Indices are zero-based; this is an explicit practice assumption resolving the source prompt's position-number ambiguity.
- For length `n`, the first half uses indices `[0, n // 2)` and the second uses `[n // 2, n)`.
- Each result is integer `1` when at least one matching index satisfies the property, otherwise `0`.
- The same occurrence may establish more than one flag.
- For an empty list, return `[0, 0, 0, 0]`.
- Do not mutate `values`.
### Hints
- You can update all four flags during one scan and stop early once all are set.
Quick Answer: Report four flags showing whether a target appears at an even index, an odd index, in the first half, and in the second half of an even-length list. Update all flags during one scan, allow one occurrence to satisfy multiple properties, and stop once all are set.
Return four binary flags for whether a target occurs at an even index, odd index, first-half index, and second-half index of an even-length list.
Constraints
- len(values) is even and at most 1000000
- Values and target are signed integers
- For empty input return four zeroes
Examples
Input: {'target': 7, 'values': [7, 2, 3, 7, 5, 6]}
Expected Output: [1, 1, 1, 1]
Explanation: Matches cover both parities and both halves.
Input: {'target': 1, 'values': []}
Expected Output: [0, 0, 0, 0]
Explanation: Empty input sets no flag.
Hints
- A matching index can establish both a parity and a half flag.
- All four flags can be updated in one scan.