Rust  22ms sort + fold
Intuition\nWe need to find minimum of max distances between same elemets\n\n# Complexity\n- Time complexity:\nO(n*log(n)) for sorting\n\n- Space complexity:\nO(
# Intuition\nWe need to find minimum of max distances between same elemets\n\n# Complexity\n- Time complexity:\n$$O(n*log(n))$$ for sorting\n\n- Space complexity:\n$$O(n)$$ for vector with indexes\n\n# Code\n```\nimpl Solution {\n    pub fn minimum_seconds(nums: Vec<i32>) -> i32 {\n        let mut idx_vec = nums\n            .iter()\n            .copied()\n            .enumerate()\n            .map(|(idx, num)| (num, idx))\n            .collect::<Vec<_>>();\n        idx_vec.sort_unstable();\n        let n = nums.len();\n        idx_vec.push((-1, n)); // pad\n        idx_vec\n            .windows(2)\n            .fold((idx_vec[0].1, 0, n), |(fist_idx, cur_max, res), lr| {\n                let (prev_num, prev_idx) = lr[0];\n                let (cur_num, cur_idx) = lr[1];\n                if prev_num == cur_num {\n                    (fist_idx, cur_max.max(cur_idx - prev_idx), res)\n                } else {\n                    (cur_idx, 0, res.min(cur_max.max(fist_idx + n - prev_idx)))\n                }\n            })\n            .2 as i32\n            / 2\n    }\n}\n```
['Sorting', 'Rust']