Tap here to switch tabs
Problem
Submissions

Problem: Array Transformation

Array Transformation repeatedly and simultaneously adjusts each interior array value: valleys rise, peaks fall, while endpoints stay fixed. Return the array once it stops changing.

Statement

Given an initial integer array arr, repeatedly modify the elements simultaneously based on the following rules:

  • An element is incremented by 11 if it is strictly smaller than both its left neighbor and its right neighbor.

  • An element is decremented by 11 if it is strictly greater than both its left neighbor and its right neighbor.

  • The first and last elements of the array never change.

This modification process is applied repeatedly until the array stops changing. Return the final modified array.

Constraints:

  • 3≤3 \leq arr.length ≤100\leq 100

  • 1≤1 \leq arr[i] ≤100\leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Array Transformation

Array Transformation repeatedly and simultaneously adjusts each interior array value: valleys rise, peaks fall, while endpoints stay fixed. Return the array once it stops changing.

Statement

Given an initial integer array arr, repeatedly modify the elements simultaneously based on the following rules:

  • An element is incremented by 11 if it is strictly smaller than both its left neighbor and its right neighbor.

  • An element is decremented by 11 if it is strictly greater than both its left neighbor and its right neighbor.

  • The first and last elements of the array never change.

This modification process is applied repeatedly until the array stops changing. Return the final modified array.

Constraints:

  • 3≤3 \leq arr.length ≤100\leq 100

  • 1≤1 \leq arr[i] ≤100\leq 100