Programming Exercises

Write a program to flatten a nested list into a single list.

Medium

Problem Statement

Write a program to flatten a nested list into a single list.

Sample Input

Nested list: [[1, 2], [3, 4], [5, [6, 7]]]

Sample Output

Flattened list: [1, 2, 3, 4, 5, 6, 7]

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
fun flattenList(nestedList: List<Any>): List<Int> { // Add your code here to flatten the nested list } fun main() { val nestedList = listOf(listOf(1, 2), listOf(3, 4), listOf(5, listOf(6, 7))) println("Flattened list: ${flattenList(nestedList)}") }
Log in or sign up to run or submit your code.Log inSign up
Input
Nested list: [[1, 2], [3, 4], [5, [6, 7]]]
Expected Output
Flattened list: [1, 2, 3, 4, 5, 6, 7]