Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Task-scheduler closed-form min total intervals: m = max letter frequency k = number of letters tied at frequency m answer = max((m - 1) * (n + 1) + k, total_tasks) For "AAABBC" with cooldown n = 2: freq A = 3, freq B = 2, freq C = 1 -> m = 3, k = 1 formula = (3 - 1) * (2 + 1) + 1 = 7 total tasks = 6 answer = 7 Witness schedule: A, B, C, A, B, idle, A. Tests String.iter with side-effecting count update via Char.code arithmetic, fixed-size 26-bucket histogram. 195 baseline programs total.
19 lines
554 B
OCaml
19 lines
554 B
OCaml
let task_intervals tasks n =
|
|
let counts = Array.make 26 0 in
|
|
String.iter (fun c -> counts.(Char.code c - Char.code 'A') <- counts.(Char.code c - Char.code 'A') + 1) tasks;
|
|
let max_c = ref 0 in
|
|
for i = 0 to 25 do
|
|
if counts.(i) > !max_c then max_c := counts.(i)
|
|
done;
|
|
let max_n = ref 0 in
|
|
for i = 0 to 25 do
|
|
if counts.(i) = !max_c then max_n := !max_n + 1
|
|
done;
|
|
let intervals = (!max_c - 1) * (n + 1) + !max_n in
|
|
let total = String.length tasks in
|
|
if intervals > total then intervals else total
|
|
|
|
;;
|
|
|
|
task_intervals "AAABBC" 2
|