Before saving a workspace, your editor compares the current pane layout with the last saved snapshot. Both are binary trees of pane ids.
Write sameLayout(a, b) that returns true when the two trees have exactly the same shape and the same id in every matching position, and false otherwise. Two empty trees are the same.
Input: a = [1,2,3], b = [1,2,3] Output: true
Same shape, same ids.
Input: a = [1,2], b = [1,null,2] Output: false
In a, 2 is a left child; in b, it is a right child.
0 <= number of nodes in each tree <= 10000Trees are written level by level, like [1, 2, 3, null, 4], where null is a missing child. Your function works with TreeNode objects, each with val, left, and right.
Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #318 Identical Layout Snapshots. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.