public static int longestRepeatingSubstr(String str)
    {
        int currLen = 1;
        int maxLen = 1;
        int prevIndex = 0;
        int[] visited = new int[256];
        
        for (int i = 0; i < visited.length; i++)
        {
            visited[i] = -1;
        }
        
        visited[str.charAt(0)] = 0;
        
        for (int i = 1; i < str.length(); i++)
        {
            prevIndex = visited[str.charAt(i)];
            
            if (prevIndex == -1 || i - currLen > prevIndex)
            {
                currLen++;
            }
            else
            {
                if (currLen > maxLen)
                    maxLen = currLen;
                
                currLen = i - prevIndex;
            }
            
            visited[str.charAt(i)] = i;
        }
        
        if (currLen > maxLen)
            maxLen = currLen;
        
        return maxLen;
    }