Your question is At Most One Swap to Sort. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
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):