insidcode
ProblemsDuelLeaderboardStats
Sign In
  1. Home
  2. Problems
  3. Rearrange an array such that positive and negative numbers alternate in position.

Rearrange an array such that positive and negative numbers alternate in position.

Difficulty: Medium

Phase: 6 · Mixed Logical Challenges

XP Reward: 20 XP

Topics: Mixed Logical Challenges, Medium

Supported Languages: Python, JavaScript, C, C++, Java

Problem Description

Given array with equal count of positive and negative integers, rearrange them so positive and negative numbers alternate starting with positive. Input Format: Read input from standard input (stdin). Output Format: Print the result to standard output (stdout).

Constraints

  • -10^9 <= N <= 10^9

Examples

Example 1

Input: 6 3 1 -2 -5 2 -4

Output: 3 -2 1 -5 2 -4

Explanation: Sample execution for input 6 3 1 -2 -5 2 -4