Apply a sequence of double, increment, negate, reverse, sort and unique operations to a list
Company: Nubank
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Other
You are given a list of integers `nums` and a list of strings `operations`. Apply the operations to `nums` one after another, in the order they appear, and return the final list.
The supported operations are:
- `"double"`: multiply every element by 2.
- `"increment"`: add 1 to every element.
- `"negate"`: multiply every element by -1.
- `"reverse"`: reverse the order of the list.
- `"sort"`: sort the list in non-decreasing order.
- `"unique"`: remove duplicates, keeping the first occurrence of each value and preserving the relative order of the kept elements.
### Function Signature
```python
def transform(nums: list[int], operations: list[str]) -> list[int]:
```
### Rules
- Each operation is applied to the list produced by the previous one. With an empty `operations` list, the answer is `nums` as given.
- `"unique"` keeps the first occurrence of each value in the list as it stands when that operation runs, so its result depends on whether `"reverse"` or `"sort"` ran before it.
- Values are exact integers. Up to 100 operations can push a value far past the 64-bit range (100 doublings multiply it by ${2^{100}}$), and the expected output holds the exact value.
### Constraints
- `0 <= len(nums) <= 10^4`
- `-10^9 <= nums[i] <= 10^9`
- `0 <= len(operations) <= 100`
- Each `operations[i]` is one of `"double"`, `"increment"`, `"negate"`, `"reverse"`, `"sort"`, `"unique"`.
### Examples
#### Example 1
```text
Input: nums = [1, 2, 3], operations = ["double", "increment"]
Output: [3, 5, 7]
```
After `"double"` the list is `[2, 4, 6]`, and `"increment"` turns it into `[3, 5, 7]`.
#### Example 2
```text
Input: nums = [3, 1, 2, 1, 3], operations = ["unique", "sort", "negate"]
Output: [-1, -2, -3]
```
`"unique"` keeps the first 3, 1 and 2, giving `[3, 1, 2]`. Sorting gives `[1, 2, 3]` and negating gives `[-1, -2, -3]`, which ends up in decreasing order because the negate ran after the sort.
#### Example 3
```text
Input: nums = [4, -1, 4, 0], operations = ["reverse", "increment", "unique", "double"]
Output: [2, 10, 0]
```
Reversing gives `[0, 4, -1, 4]` and incrementing gives `[1, 5, 0, 5]`. `"unique"` drops the second 5, leaving `[1, 5, 0]`, and doubling gives `[2, 10, 0]`.
Overview: Given a list of integers and a sequence of named operations (double, increment, negate, reverse, sort, unique), return the list after applying them in order. It tests careful step-by-step simulation, order-preserving deduplication and reasoning about the cost of each operation.