Track And Calculate Same Item's Distance
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```csharp []
public class Solution {
    private int MinDist(List<int> ids, int len)
    {
        int maxDist = 0, size = ids.Count;
        for(int i = 0; i < size; i++)
        {
            int start = ids[i], end = i < size-1 ? ids[i+1] : ids[0]+len;
            maxDist = Math.Max(maxDist, end-start-1);
        }

        return maxDist%2 + maxDist/2;
    }

    public int MinimumSeconds(IList<int> nums) {
        Dictionary<int, List<int>> dict = new();
        int len = nums.Count;
        if(len < 2)
            return 0;
        int maxSec = len-1;
        for(int i = 0; i < len; i++)
        {
            int n = nums[i];
            if(!dict.ContainsKey(n))
                dict.Add(n, new List<int>());
                
            dict[n].Add(i);
        }

        if(dict.Count == 1) // All items are same
            return 0;

        bool hasSingle = false;

        foreach(var kvp in dict)
        {
            if(kvp.Value.Count > 1)
            {
                int curDist = MinDist(kvp.Value, len);
                maxSec = Math.Min(maxSec, curDist);
            }
            else
              hasSingle = true;
        }
        
        if(hasSingle)
        {
            int cnt = len-1;
            maxSec = Math.Min(maxSec, cnt%2 + cnt/2);
        }

        return maxSec;
    }
}
```
['C#']