Flatten 2D Array

EasyData EngineeringMatrixArraySorting

Description

Given a 2D array matrix, return all elements flattened into a single array in row-major order.

Examples

Input:matrix = [[1,2],[3,4]]
Output:[1,2,3,4]
Explanation:

Concatenating the rows in order yields [1,2,3,4].

Input:matrix = [[5]]
Output:[5]
Explanation:

Concatenating the rows in order yields [5].

Input:matrix = [[1],[2],[3]]
Output:[1,2,3]
Explanation:

Concatenating the rows in order yields [1,2,3].

Constraints

  • 1 ≤ rows, cols ≤ 100

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.