The TransCompilator

Solved LeetCode program · 854 of 1,000

#1145 · Binary Tree Coloring Game

Medium Depth-First Search chunk-18.md

Original English source

The values is a list of 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, and 11. The count is 11. Keep a shared lefts as an empty list of whole numbers. Keep a shared rights as an empty list of whole numbers.
For every node from 0 to 10.
The left is node times 2 plus 1. The right is node times 2 plus 2. If left is at least count, set left to -1. If right is at least count, set right to -1. Place left into lefts. Place right into rights.

Keep a shared counted of 0.

To tally from node (a whole number). If node is less than 0, set counted to 0, return. The left is item node of lefts. The right is item node of rights. Tally from left. The leftsize is counted. Tally from right. The rightsize is counted. Set counted to leftsize plus rightsize plus 1.

The chosen is 3. The red is chosen minus 1. Tally from item red of lefts. The leftsize is counted. Tally from item red of rights. The rightsize is counted. Tally from red. The redsize is counted. The rest is count minus redsize. The bigger is the larger of leftsize and rightsize. The biggest is the larger of bigger and rest. If biggest times 2 is more than count, show true, otherwise show false.

Open in Playground Browse all 1,000 problems

Expected stdout

true