DEV Community

Saranya R
Saranya R

Posted on

Move All Negative Elements to end

Approach Explanation o( ̄▽ ̄)o

  1. I collected positives and negatives separately.
  2. I concatenated them in the correct order.
  3. I reassigned the result back to arr[:] so the original array is updated.
  4. This way, positives stay at the front, negatives move to the end, and the order is preserved.

Methods Used: (* ̄o ̄)/

  • List comprehension
  • Stable partition method
  • Single traversal
  • Extra space

Top comments (0)