InferenceAI

Enter at least two characters to search.

Start free

Symmetric Tree

easyTrees15 min10 XP

Return True if the binary tree is symmetric around its centre.

Trees are given in level order as a list, with None for a missing child (for example [3, 9, 20, None, None, 15, 7]).

Examples

EXAMPLE WALKTHROUGHsymmetric

A guided view of the published example, not a trace of your code.

INPUT[[1,2,2,3,4,4,3]]
TASKsymmetric_tree()
EXPECTED OUTPUTtrue

Start with the input values shown in this example.

Example 1 of 3

Input: values = [1,2,2,3,4,4,3]

Output: true

Explanation: symmetric

Input: values = [1,2,2,null,3,null,3]

Output: false

Explanation: not symmetric

Input: values = []

Output: true

Explanation: empty

Hint 1

Compare the left subtree with the mirror of the right: left.left with right.right and left.right with right.left.

Topics

DSATreesPython