ALN - EDITORIAL

Difficulty: Easy

Prerequisites: Sorting

Problem link:

Contest problem link

Practice problem link

Problem

Given an array of -1s and 1s arrange -1s to the left and 1s to the right.

Explanation

One way of solving the problem is to sort the array. Complexity in this case would be O(n log n), considering sorting is done through a divide and conquer approach.

The best approach is to count the number of -1s and 1s in counters (lets say c1 and c2 respectively) and print -1, c1 times and 1 c2 times. Complexity in this case would be O(n).

Problem setter’s solution. SOLUTION

//