import java.util.*;
public class SummaryRanges {

    public static List<String> summaryRanges(int[] nums) 
    {
        List<String> result = new ArrayList<>();

        if (nums == null || nums.length == 0)
        {
            return result;
        }

        int start = nums[0];

        for (int i = 1; i <= nums.length; i++) 
        {
            if (i == nums.length || nums[i] != nums[i - 1] + 1) 
            {
                if (start == nums[i - 1]) 
                {
                    result.add(String.valueOf(start));
                } 
                else 
                {
                    result.add(start + "->" + nums[i - 1]);
                }
                
                if (i < nums.length) 
                {
                    start = nums[i];
                }
            }
        }

        return result;
    }

    public static void main(String[] args) {
        //int[] nums = new int[]{0,2,3,4,6,8,9};   //Test case 1    PASS             Junction 2,6,10,11,12,3,5,14,13,4
        //int[] nums = new int[]{-1};   //Test case 2             PASS             Junction 1
        //int[] nums = new int[]{0};   //Test case 3       PASS                    Junction 1
        //int[] nums = new int[]{0,1,2,4,5,7};   //Test case 4    PASS            Junction 2,3,5,6,10,14,9,7
        
        //For some reason, no test cases above went through junction 8. All others are valid.
        //So I devised a new test case below and it passes through it...
        
        //new test case:
        //int[] nums = new int[]{0,1,2,4,5,7,8,10,14};   //Test case 4    PASS            //Junction 2,3,5,6,10,14,7,8
        //int[] nums = new int[]{0,1,2,4,5,7,8,10,14,17,19,23,24,25,26,35,42,43,44};        //Junction 2,3,5,6,10,14,7,8,11,13,16
        //int[] nums = new int[]{0,1,2,4,5,7,8,10,14,17,19,23,24,25,26,35,42,47};
        int[] nums = new int[]{0,2,4,5,7,8,10,14,17,19,23,24,25,26,35,42,47,58,49,50,51,55,57,59,60};
        List<String> output = summaryRanges(nums);
        System.out.println(output);  // Output: [0->2, 4->5, 7]    }
}