# How to perform cyclic sort on an array def cyclic_sort(nums): for i in range(len(nums)): # Traversing the array from the first index to the last index # Determining what position the specific element should be at correct_spot = nums[i] - 1 while 1 <= nums[i] <= len(nums) and nums[i] != nums[correct_spot]: nums[i], nums[correct_spot] = nums[correct_spot], nums[i] correct_spot = nums[i] - 1