DEV Community
•
2026-03-20 03:10
Move Negative Elements to End While Maintaining Order
Problem Statement:
Given an unsorted array containing both positive and negative integers, rearrange the array such that all negative elements are moved to the end without changing the order of positive and negative elements.
Example:
Input: [1, -1, 3, 2, -7, -5, 11, 6]
Output: [1, 3, 2, 11, 6, -1, -7, -5]
Approach:
We use two separate lists:
One for positive elements
One for negative elements...