+ 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 ответов
+ 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