Petri plate O(n)
Intuition\nDigits are spreading exactly the same as bacterias in Petri\'s plate.\nWe need to find the one that distributed evenly across the plate - it take all
# Intuition\nDigits are spreading exactly the same as bacterias in Petri\'s plate.\nWe need to find the one that distributed evenly across the plate - it take all space faster then others.\n\n# Approach\nCollect indexes for each digit.\nCalculate max distances to pass for each digit.\nTake smallest of these and divide it by 2 (since it is filling the space from both sides)\n\n# Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\n# @param {Integer[]} nums\n# @return {Integer}\ndef minimum_seconds(nums)\n  nums\n    .each_with_index\n    .reduce({}) { |m, (n, idx)| m[n] ||= []; m[n].push(idx); m }\n    .values\n    .map { |v|  v.each_cons(2).map { |(a,b)| b-a }.push(nums.size - v[-1] + v[0]).max }\n    .min / 2\nend\n```
['Ruby']