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]
Lessons in this chapter · Practice with Common Coding Quiz Types
- 1. Coding Quiz - Finding Rotten Apples
- 2. Finding Rotten Apples Explained
- 3. Coding Quiz - Calculating the Sum of a List Recursively
- 4. Explanation for Recursively Calculating the Sum of a List
- 5. Coding Quiz - 1, 2, 3 Addition
- 6. Explanation for Adding 1, 2, 3
- 7. Coding Quiz - Flattening a 2D Array
- 8. Converting to a 1D Array Explanation
- 9. Coding Quiz - Calculate the Sum of a List Using Divide and Conquer
- 10. Explanation of Calculating the Sum of a List Using Divide and Conquer
- 11. Coding Quiz - Gym Uniform Problem
- 12. Gym Uniform Problem Explanation
- 13. Coding Quiz - List of Integers with Sum Greater than Target
- 14. Explanation of Integer List with Sum Greater Than Target
- 15. Coding Quiz - Finding Travel Routes
- 16. Finding Travel Itinerary Explanation
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help