Skip to content

Commit bb3b75e

Browse files
committed
Updates from code review
1 parent d1b4253 commit bb3b75e

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

greatfrontend/blind-75/trees/level-order-traversal/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Binary Tree Level Order Traversal
1+
# Binary Tree Level Order Traversal ![Medium](https://img.shields.io/badge/Medium-orange)
2+
3+
[GreatFrontEnd Problem Link](https://www.greatfrontend.com/interviews/study/blind75/questions/algo/binary-tree-level-order-traversal)
24

35
Given the root node of a binary tree, return an array of arrays, where each inner array represents the values of nodes at each level of the tree, traversed from left to right.
46

greatfrontend/blind-75/trees/level-order-traversal/binary-tree-level-order-traversal.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,55 @@ describe('binaryTreeLevelOrderTraversal', () => {
3939
const result = binaryTreeLevelOrderTraversal(root);
4040
expect(result).toEqual([[1], [2, 3], [4]]);
4141
});
42+
43+
it('should match the example with a negative value', () => {
44+
const root: TreeNode = {
45+
val: 13,
46+
left: null,
47+
right: { val: -55, left: null, right: null }
48+
};
49+
expect(binaryTreeLevelOrderTraversal(root)).toEqual([[13], [-55]]);
50+
});
51+
52+
it('should match the full three-level example', () => {
53+
const root: TreeNode = {
54+
val: 1,
55+
left: {
56+
val: 2,
57+
left: { val: 4, left: null, right: null },
58+
right: { val: 5, left: null, right: null }
59+
},
60+
right: {
61+
val: 3,
62+
left: { val: 6, left: null, right: null },
63+
right: { val: 7, left: null, right: null }
64+
}
65+
};
66+
expect(binaryTreeLevelOrderTraversal(root)).toEqual([
67+
[1],
68+
[2, 3],
69+
[4, 5, 6, 7]
70+
]);
71+
});
72+
73+
it('should match the example with missing left child', () => {
74+
const root: TreeNode = {
75+
val: 5,
76+
left: {
77+
val: 3,
78+
left: null,
79+
right: { val: 4, left: null, right: null }
80+
},
81+
right: {
82+
val: 8,
83+
left: { val: 7, left: null, right: null },
84+
right: { val: 9, left: null, right: null }
85+
}
86+
};
87+
expect(binaryTreeLevelOrderTraversal(root)).toEqual([
88+
[5],
89+
[3, 8],
90+
[4, 7, 9]
91+
]);
92+
});
4293
});

0 commit comments

Comments
 (0)