Lecture

Coding Quiz - Flattening a 2D Array

In this coding quiz, you will write a function that flattens a given 2D array into a 1D array.

You will receive a 2D array (a list of lists) from the user and return a 1D array containing all elements.

Elements in the 1D array should be placed in the order they appear in the 2D array.


Code Implementation
def solution(matrix): # Write your code here return



Constraints

  • The sub-arrays of the 2D array given as input may or may not have the same length.

  • Array elements can be integers.




Example Input/Output

  • Input: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

  • Output: [1, 2, 3, 4, 5, 6, 7, 8, 9]

Lecture

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help