Scala Programming: Remove the duplicate elements of a given array and return the new length of the array
Write a Scala program to remove the duplicate elements of a given sorted array and return the new length of the array.
Sample array: [20, 20, 30, 40, 50, 50, 50, 50, 60, 60]
After removing the duplicate elements the program should return 5 as the new length of the array
Sample Solution:
Scala Code:
Sample Output:
Original array length: 10 Array elements are: 20 20 30 40 50 50 50 50 60 60 The new length of the array after removing the duplicate elements is: 5
Scala Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Next: Write a Scala program to find smallest and second smallest elements of a given array.What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics