You are given an array of n integers, both negative and
positive. You need to partition them into two different arrays
without directly comparing any element to 0, 1, -1 or any other
fixed value. Consider 0 as a positive number. If arr[0] is a
positive number, then print all the positive numbers in the given
order in the first line of output and then all the negative numbers
in the given order in the second line of output, vice - versa.
Note:
Input: The input should be in the following format:
Output: The output should be in the following format:
Sample test case:
Input:
Output:
import java.util.*;
public class Source {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
int n = sc.nextInt();
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr =
sc.nextInt();
}
partitionNegativeAndPositive(n,
arr);
}
// Method to partition negative and positive
numbers without comparing with 0
static void partitionNegativeAndPositive(int n, int
arr[]) {
// Write your code here
}
}
You are given an array of n integers, both negative and positive. You need to partition them into two different arrays w
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
You are given an array of n integers, both negative and positive. You need to partition them into two different arrays w
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!