The diagram below shows a binary tree representation of an Operating System course and its prerequisites.
Write a function that returns the level order traversal of the courses.
const levelOrder = (root) => {
// Enter your logic here...
}
Examples:
Input: [Operating Systems, Computer Architecture, Algorithms, Digital Logic, Data Structures]
Output: [[Operating Systems], [Computer Architecture, Algorithms], [Digital Logic, Data Structures]]
Explanation: Each subarray contains the courses at a specific level of the binary tree structure.
Input: [Operating Systems]
Output: [[Operating Systems]]
Explanation: Each subarray contains the courses at a specific level of the binary tree structure.
Date
Code
Code Editor
Test Case
Input
Expected Output
Test Case 1
[Operating Systems, Computer Architecture, Algorithms, Digital Logic, Data Structures]
[[Operating Systems], [Computer Architecture, Algorithms], [Digital Logic, Data Structures]]