+ 7

Array sorting Challenge

sort an array of elements containing positive and negative numbers The Negative numbers should take the odd positions starting with negative number and then followed by positive numbers. If the array contains more number of positive or negative irrespectively then the left over numbers should take remaining positions. case 1:- array are{2,6,-8,9,0,-2,-5} output:- -8 0 -5 2 -2 6 9 Conditions:- 1) try with one array. 2) Treat 0 as positive number. 3) Use any language. 4)Return null if array is empty.

19th Sep 2017, 1:36 PM
$@|!VĀ£Ā®U $@! |<U^^@Ā®
$@|!VĀ£Ā®U   $@!    |<U^^@Ā® - avatar
8 Answers
+ 9
Here's my C# implementation āœŒ No LINQ One-Liner but TWO this time as I couldn't make it without complicating things. Anyway it fully utilize the LINQ feature and work with any number of positive and negative numbers. Enjoy! https://code.sololearn.com/cBohh2LE7g88/?ref=app
20th Sep 2017, 4:18 PM
Zephyr Koo
Zephyr Koo - avatar
19th Sep 2017, 4:15 PM
m abrate
m abrate - avatar
+ 6
@luka & @sayan There's a bug in your program which failed to pass [-1, 2, 3].
20th Sep 2017, 4:21 PM
Zephyr Koo
Zephyr Koo - avatar
+ 2
can you try the same using only single array in JAVA
20th Sep 2017, 3:33 AM
$@|!VĀ£Ā®U $@! |<U^^@Ā®
$@|!VĀ£Ā®U   $@!    |<U^^@Ā® - avatar
+ 2
conditions have been modified please go through
20th Sep 2017, 7:20 AM
$@|!VĀ£Ā®U $@! |<U^^@Ā®
$@|!VĀ£Ā®U   $@!    |<U^^@Ā® - avatar
19th Sep 2017, 3:47 PM
sayan chandra
sayan chandra - avatar
0
@@@ luka @@@ Ekansh HAVE U READ THE CHALLENGE...???? ITS TOTALLY DIFFERENT THAN SIMPLE ARRAY SORT THAT YOU DID.
19th Sep 2017, 3:39 PM
sayan chandra
sayan chandra - avatar
- 1
u need another 2 array... for keeping positive and negetive nums of initial array...
20th Sep 2017, 3:52 AM
sayan chandra
sayan chandra - avatar