As reported: Glean new grad final round (2025), second session (one hour, LeetCode style), question 1 (medium): given a sorted array with one element out of place, write a function that sorts it.
An array of integers was sorted in non-decreasing order; then exactly one element was taken out and inserted at some other position (possibly the same position). Return the sorted array. Aim for O(n) time.
Example 1
nums = [1,2,9,3,4,5] -> [1,2,3,4,5,9]
Example 2
nums = [3,5,6,8,1,9] -> [1,3,5,6,8,9]
Constraints: 1 ≤ nums.length ≤ 10^5; -10^9 ≤ nums[i] ≤ 10^9; the input is a sorted array with at most one element moved; values may repeat.
Code runner format: one JSON value: nums. Implement fixOneOutOfPlace(nums); the harness prints the sorted array.