Scala Programming: Flatten a given List of Lists, nested list structure
Write a Scala program to flatten a given List of Lists, nested list structure.
Sample Solution:
Scala Code:
Sample Output:
Original List: List(List(1, 3, 5, 7), List(2, 4, 6, 8), List(31, 32, 33, 34)) Flatten list: List(1, 3, 5, 7, 2, 4, 6, 8, 31, 32, 33, 34) Original List: List(1, List(2, 3, 4), List(List(List(5, 6, 7))), List(8, 9), List(10), 11) Flatten list: List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
Scala Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Scala program to check a given list is a palindrome or not.
Next: Write a Scala program to triplicate each element immediately next to the given list of integers.
What is the difficulty level of this exercise?