The TransCompilator

Solved LeetCode program · 771 of 1,000

#1007 · Minimum Domino Rotations For Equal Row

Medium Array chunk-16.md

Original English source

Keep a shared tops holding 2, 1, 2, 4, 2, and 2. Keep a shared bottoms holding 5, 2, 6, 2, 3, and 2. Keep a shared best of 0.

To check with candidate (a whole number). The possible is 1. The topcost is 0. The bottomcost is 0.
For every spot from 0 to 5.
If item spot of tops is not candidate and item spot of bottoms is not candidate, set possible to 0. If item spot of tops is not candidate, add 1 to topcost. If item spot of bottoms is not candidate, add 1 to bottomcost. If spot is 5, The take is the smaller of topcost and bottomcost, If possible is 1 and take is less than best, set best to take.

Set best to 100. The firsttop is item 0 of tops. The firstbottom is item 0 of bottoms. Check with firsttop. Check with firstbottom. If best is 100, show -1, otherwise show best.

Open in Playground Browse all 1,000 problems

Expected stdout

2