Company: Amazon_29may
Difficulty: medium
Slot Machine 2.0 Problem Description A slot machine has several wheels. Each wheel is manufactured with some number of stops, and a wheel built with c stops can display any digit d with 0 <= d <= c . Building a wheel with c stops costs c ; the total cost of the machine is the sum of the stop counts of all its wheels. The machine has been spun n times. During each spin every wheel comes to rest and shows one digit, so each spin produces one digit per wheel. The digits observed in a spin are recorded as a string in history . All recorded strings have the same length, and that length is the number of wheels. The recording does not say which wheel produced which digit: for one spin only the multiset of digits matters, and the wheels may be matched to the recorded digits differently from one spin to the next. You are given history . Determine the smallest possible total number of stops over all wheels such that every spin in history could have been produced by that machine. Function I