Same Tree
Hard · Data Structures
Nested maps with Val and optional Left/Right. Write sameTree(_:_:) for two [String: Any]? encoded as JSON objects (use [String: Int] leaves only — tests use Val plus nested dicts via a flattened encoding).
Tests pass preorder arrays: [val, leftVal or -1, rightVal or -1] is too lossy. Instead compare two JSON-like dicts built as ["Val": n] only for these tests, plus one nested via runSame.
Write runSame(_ a: [Int], _ b: [Int]) where each array is a preorder with -1 for nil of a full binary tree stored heap-like in an array (i has children 2i+1, 2i+2).
Next: Merge JSON Objects