NVIDIA VO Coding Interview: Non-decreasing Array and Find Original Array From Doubled Array

16 Views
No Comments

Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element.

We define an array as non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based) such that 0 <= i <= n - 2.

Given an array changed, return original if changed is a doubled array. If changed is not a doubled array, return an empty array.

The elements in original may be returned in any order.

This prompt combines two classic array interview problems. The first checks whether an array can be made non-decreasing with at most one modification, which is typically solved by scanning for inversions and greedily adjusting one of the two conflicting values. The second asks for the original array from a shuffled doubled array, usually requiring sorting and careful frequency matching between each number and its double. Both problems test array reasoning, edge cases, and greedy or counting techniques.

END
 0