Desafio semanal Buk - 23 de Mayo - diegoheg
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n# @param {Integer[]} nums\n# @return {Integer}\n# Se reemplaza la posici\xF3n del array\n# consigo mismo o con sus vecinos\ndef minimum_seconds(nums)\n  n = nums.size\n  ocurrences = Hash.new { |hash, key| hash[key] = [] }\n  nums.each_with_index do |num, index|\n    ocurrences[num] << index\n  end\n\n  total_seconds = {}\n  return 0 if ocurrences.keys.size == 1\n\n  puts ocurrences\n\n  ocurrences.each do |num, indexes|\n    max_seconds = 0\n    m = indexes.size\n    (0..(m - 1)).each do |aux_index|\n      if aux_index == (m - 1)\n        rms = n - indexes[aux_index] + indexes[0]\n      else\n        rms = indexes[aux_index + 1] - indexes[aux_index]\n      end\n      rms = (rms / 2).to_i\n      if rms > max_seconds\n        max_seconds = rms\n      end\n    end\n    if max_seconds.zero?\n      total_seconds[num] = (n / 2).to_i\n    else\n      total_seconds[num] = max_seconds\n    end\n  end\n\n  total_seconds.min_by{|_k, v| v}.last\nend\n\n```
['Ruby']