The TransCompilator

Solved LeetCode program · 922 of 1,000

#1283 · Find the Smallest Divisor Given a Threshold

Medium Array chunk-19.md

Original English source

Keep a shared values holding 1, 2, 5, and 9. Keep a shared total of 0. The limit is 6.

To measure from divisor (a whole number). Set total to 0.
For each value in values.
The share is value divided by divisor. If value modulo divisor is not 0, add 1 to share. Add share to total.

The low is 1. The high is 0. For each value in values, if value is more than high, set high to value. The answer is high.
Repeat while low is at most high.
The middle is the midpoint of low and high. Measure from middle. If total is at most limit, set answer to middle, set high to middle minus 1. If total is more than limit, set low to middle plus 1.

Show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

5