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
You can use 2 queues and merge them. That way, you only iterate once on the first array and once each sub queue.
negatives = [] positives = [] for elem in array: if elem >= 0: positives.push(elem) else negatives.push(elem) result = array(negatives, positives)