Scala Programming: Segregate all 0s on left side and all 1s on right side of a given array of 0s and 1s
Write a Scala program to segregate all 0s on left side and all 1s on right side of a given array of 0s and 1s.
Sample Solution:
Scala Code:
Sample Output:
Original array: 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, Array after segregation array becomes: 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
Scala Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Scala program to find smallest and second smallest elements of a given array.
Next: Write a Scala program to find the two elements from a given array of positive and negative numbers such that their sum is closest to zero.
What is the difficulty level of this exercise?