HERE Technologies uses ordered location data in workflows such as HERE Map Content validation. Given an array of integers, determine whether it can be sorted in nondecreasing order using at most one swap of two elements.
A swap exchanges the values at any two distinct indices. The array may also require no change. Return True if the condition can be satisfied, otherwise return False.
Implement can_be_sorted_by_one_swap(nums).
nums, a list of integers.nums nondecreasing.nums.def can_be_sorted_by_one_swap(nums):