Back to course home
0% completed
Solution: Array Transformation
Problem Statement
Given an array arr
, you transform it daily based on the following rules:
- If an element is smaller than both its left and right neighbors, increment it by
1
. - If an element is larger than both its left and right neighbors, decrement it by
1
. - The first and last elements of the array do not change.
Continue transforming the array until no more changes occur. Return the final state of the array.
Examples
Example 1
- Input: arr =
[5, 2, 8, 1, 6]
- Expected Output:
[5, 5, 5, 5, 6]
- Justification:
.....
.....
.....
Like the course? Get enrolled and start learning!