Scala Programming: Find smallest and second smallest elements of a given array
Write a Scala program to find smallest and second smallest elements of a given array.
Sample Solution:
Scala Code:
Sample Output:
Original array: 5, 6, -9, 6, 15, 4, The smallest element is -9 and second Smallest element is 4.
Scala Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Scala program to remove the duplicate elements of a given sorted array and return the new length of the array.
Next: 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.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics