File: array-transformation/solution.py

Date: 2026-06-06

Time: 15:16

array-transformation/solution.py

This solves LeetCode 1243 - Array Transformation. The problem: repeatedly adjust interior elements that are strict local minima (bump up by 1) or strict local maxima (bump down by 1), until the array stops changing.

Key Components

array_transformation(arr: List[int]) -> List[int] — the sole export. Takes an integer array, returns the stable result after all transformations complete.

Flow

1. Defensive copy (arr = arr[:]) — avoids mutating the caller's list.

2. Fixed-point loop (while True) — each iteration applies one round of transformations simultaneously:

3. Convergence check — if new == arr, the array is stable and returned. Otherwise arr = new and we loop.

Patterns

Dependencies

Invariants

Error Handling

None. The function assumes valid input (list of at least 1 integer, per the LeetCode constraints). An empty list would return immediately since the inner loop wouldn't execute and new == arr on the first check. A single-element list behaves the same way.

Topics to Explore

Beliefs