As reported: Morgan Stanley Java developer (8.5 years of experience, Bangalore) virtual hiring drive, Mar 2026: four rounds mixing Java questions and LeetCode-style coding, in Java unless the interviewer allowed another language. Round 3 (techno-managerial), after the parking-lot design: rearrange an array so the negatives are on the left and the positives on the right, preserving their relative order, without extra space; given the round's constraints an
O(n²)approach was acceptable.
Given an integer array nums with no zeros, rearrange it in place so that all negative numbers come before all positive numbers, and the relative order of the negatives — and of the positives — is the same as in the input. Use O(1) extra space (apart from recursion, if you use it).
Example 1
nums = [20,-10,30,40,-50,-60,70] -> [-10,-50,-60,20,30,40,70]
Example 2
nums = [-1,2,-3,4] -> [-1,-3,2,4]
Constraints: 1 ≤ nums.length ≤ 2 · 10^4; nums[i] ≠ 0; |nums[i]| ≤ 10^9.
Code runner format: one JSON value per line: nums. Implement rearrange(nums), modifying nums in place; the harness prints nums afterwards. (The judge checks the result; the space limit is yours to keep.)