As reported: LinkedIn SSE (Apr 2025), coding round 2: check whether two trees are the same, then the shortest distance between LinkedIn connections.
Given the roots of two binary trees p and q, return true if they are the same: structurally identical, with equal values in corresponding nodes.
This is LeetCode 100 — Same Tree.
Example 1
p = [1,2,3], q = [1,2,3]
Output: true
Example 2
p = [1,2], q = [1,null,2]
Output: false
Constraints: 0 ≤ number of nodes ≤ 100 in each tree; −10^4 ≤ Node.val ≤ 10^4.
Code runner format: LeetCode's test-case format, one JSON value per line (one line per argument). The two lines are the trees in level order. Implement isSameTree(p, q); the harness prints the result.