Skip to main content

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.





Comment

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