Given an array of positive and negative numbers, arrange them such that all negative integers appear before all the positive integers in the array. The order of appearance should be maintained.
Input : arr = [12, 11, -13, -5, 6, -7, 5, -3, -6] Output : arr = [-13, -5, -7, -3, -6, 12, 11, 6, 5] Input : arr = [-12, 11, 0, -5, 6, -7, 5, -3, -6] Output : arr = [-12, -5, -7, -3, -6, 11, 0, 6, 5]
arr = [-13, -5, -7, -3, -6, 12, 11, 6, 5]
This article is contributed by Shashank Mishra (Gullu). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Rearrange positive and negative numbers using inbuilt sort function
- Rearrange positive and negative numbers with constant extra space
- Rearrange positive and negative numbers in O(n) time and O(1) extra space
- Python | Rearrange Positive and Negative Elements
- Rearrange array in alternating positive & negative items with O(1) extra space | Set 1
- Rearrange array in alternating positive & negative items with O(1) extra space | Set 2
- Python program to count positive and negative numbers in a list
- Map function and Lambda expression in Python to replace characters
- Find ratio of zeroes, positive numbers and negative numbers in the Array
- Intersection of two arrays in Python ( Lambda expression and filter function )
- C program to count Positive and Negative numbers in an Array
- Move all negative numbers to beginning and positive to end with constant extra space
- Replace all elements by difference of sums of positive and negative numbers after that element
- Check if array elements are consecutive in O(n) time and O(1) space (Handles Both Positive and negative numbers)
- Python | Find the Number Occurring Odd Number of Times using Lambda expression and reduce function
Improved By : nidhi_biet