Extract Column

MediumData EngineeringMatrixArrayMath

Description

Given a 2D array matrix (rows of equal length) and a column index col, return the values in that column as an array, top to bottom.

Examples

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

Reading column 1 from each row yields [2,5].

Input:matrix = [[7,8],[9,10]], col = 0
Output:[7,9]
Explanation:

Reading column 0 from each row yields [7,9].

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

Reading column 1 from each row yields [2,4,6].

Constraints

  • 0 ≤ col < number of columns

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.