Move all negative elements at the end of array
Given an array of integer values which are contain negative and positive values. And our goal is to move all negative elements at the end of array without using any extra space. Order of negative elements are not important. For example.
Example A
Before :
arr1 [] = {1 , -1 , 3 , 2 , -7 , -5 , 11 , 6}
After Move :
arr1 [] = {1, 6, 3, 2, 11, -5, -7, -1}
Example B
Before :
arr2 [] = {-1, -5, 3, 2, -7, -5, 11, -6}
After Move :
arr2 [] = {11, 2, 3, -5, -7, -5, -1, -6}
Here given code implementation process, Which takes O(n) time.
-
1) Move all negative elements to end in java
2) Move all negative elements to end in c++
3) Move all negative elements to end in c
4) Move all negative elements to end in c#
5) Move all negative elements to end in golang
6) Move all negative elements to end in node js
7) Move all negative elements to end in python
8) Move all negative elements to end in ruby
9) Move all negative elements to end in php
10) Move all negative elements to end in scala
11) Move all negative elements to end in swift
12) Move all negative elements to end in kotlin
13) Move all negative elements to end in vb.net
14) Move all negative elements to end in typescript
Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.
New Comment