Given an array of integers and a target value, return array such that the values that are less than target should be on left side of the array and values that are greater than target should be on right side of the array. Values that are equal to target should be in between other values.
Example:
nums = [9, 12, 5, 10, 14, 3, 10], target = 10
return = [9, 5, 3, 10, 10, 12, 14]
nums=[-3, 4, 3, 2], target = 2
Output: [-3, 2, 4, 3]Explanation and Solution:
Solving The Coding Question From Amazon Interview
Question 2:
You are given an array of integers and value k. Values in array are displaced by up to k position. Return the sorted array in most optimal way.
Example:
nums = [20, 30, 10, 40, 60, 50, 70, 100, 80, 90], k = 2
return = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]My answer was in O(nlogk)