The TransCompilator

Solved LeetCode program · 733 of 1,000

#0968 · Binary Tree Cameras

Hard Dynamic Programming chunk-15.md

Original English source

Keep a shared lefts holding 1, 3, -1, -1, and -1. Keep a shared rights holding -1, 4, -1, -1, and -1. Keep a shared marks as an empty list of whole numbers.
For every spot from 0 to 4.
Place 0 into marks.

The cameras is 0. The node is 4.
Repeat while node is at least 0.
The left is item node of lefts. The right is item node of rights. The state is 0. If left is at least 0 and item left of marks is 0, set state to 2. If right is at least 0 and item right of marks is 0, set state to 2. If state is 0 and left is at least 0 and item left of marks is 2, set state to 1. If state is 0 and right is at least 0 and item right of marks is 2, set state to 1. If state is 2, add 1 to cameras. Set item node of marks to state. Subtract 1 from node.

If item 0 of marks is 0, add 1 to cameras. Show cameras.

Open in Playground Browse all 1,000 problems

Expected stdout

1