I recently came across a Microsoft Interview Question for Software Engineer.
Given an array of positive and negative integers, re-arrange it so that you
Here is my solution in Python, using recursion (I had an assignment like this, where the array should be sorted relatively to a number K. If You put K = 0, You've got Your solution, without retaining the order of appearance):
def kPart(s, k):
if len(s) == 1:
return s
else:
if s[0] > k:
return kPart(s[1:], k) + [s[0]]
else:
return [s[0]] + kPart(s[1:], k)