import java.util.*;

public class Solution 
{
    public static void main (String[] args)
    {
        //int[] nums = new int[]{0,2,3,4,6,8,9};   //Test case 1 
        //int[] nums = new int[]{-1};   //Test case 2
        //int[] nums = new int[]{0};   //Test case 3
        int[] nums = new int[]{0,1,2,4,5,7};   //Test case 4
        
        System.out.println(summaryRanges(nums));
    }
    
    public static List<String> summaryRanges(int[] nums) 
    {
        List<String> sm = new ArrayList<>();  //List is returned to the method as prescribed in challenge
        int counter = 0;  //this is used to monitor amount of consecutive numbers. useful to ascertain if standalone numbers....
        String start=""; //this will take value of index at nums based on start of ascending sequence. Useful for multi-consecutive or standalone number
        String end="";  //this will take value of end of the ascending sequence


        //this can not be in the for loop, since if the length is 1,  condition is nums.length -1  = 1-1  = 0
        //so for loop will not execute at all.
    
        //this will simply place the single standalone number in the array into the List
        if (nums.length==1)
        {
            sm.add(String.valueOf(nums[0]));
            return sm;
        }
    
        //using nums.length-1  as the condition to prevent ArrayIndexOutOfBoundsException when comparing next element.
    
        for (int k=0; k<nums.length-1;k++)
        {
            System.out.println("value k: " + k);
            System.out.println("length nums: " + nums.length);
            
            //the first index will always be the start.
            //it will become evident later why this had to be declared exclusively
            //apart from the loop below,   start is only set once it has terminated a range X->Y or if the counter is 0
            //but clearly it is required for Test case 4, due to consecutive 0,1,2
            //otherwise following output
            
            //Your Result (Test Case 4)
            //["->2", "4->5", "7"]
            
            //However it is not as critical for Test Case 1 since 0 is standalone
            //Your Result (Test Case 1) 
            //["0", "2->4", "6", "8->9"]

            
            if (k==0)
            {
                start = String.valueOf(nums[k]);
            }
            
            //if the next element is NOT ascending by 1
            if (nums[k]+1 != nums[k+1])
            {
                System.out.println("nums[k]: " + nums[k]);
                System.out.println("nums[k+1]: " + nums[k+1]);
                System.out.println("Value of counter: " + counter);
                
                //The end will be the current element at index k
                end = String.valueOf(nums[k]);
                
                //but if the counter is 0... This will become clear. This is stating that it had no descending number before or after
                //then it needs to store the standalone number, and not the range
                
                if (counter==0)
                {
                    sm.add(String.valueOf(nums[k]));
                    System.out.println("Standalone: " + nums[k]);
                    
                    //it now declares the start to be the next number in the array
                    start = String.valueOf(nums[k+1]);
                }
                
                //this still deals with the ascending sequence coming to a halt..
                //but we know that counter is >0  (i.e minimum two numbers), so the range has to be written in expected manner
                //X->Y
                else
                {
                    System.out.println("finalise: " + k);
                    System.out.println(start+"->"+end);    
                    sm.add(start+"->"+end);
                    
                    //ready to start again
                    counter=0;
                    
                    //starting from next element
                    start = String.valueOf(nums[k+1]);
                    
                    //we need this analysis in order to pass Test Case 4
                    //since we do not officially process the last index of nums in the for loop
                    //this number has to be stored as standalone since we know that the range X->Y has been terminated
                    if((k+1)==(nums.length-1))
                    {
                        sm.add(String.valueOf(nums[k+1]));
                    }
                }
            }
            
            //on basis that it is consecutive from established start
            //seems odd that it is in the else section
            //I iniitially had this in the main if, but it seemed odd having so much more content developing in the
            //else statement, so I flipped logic in the if statement...
            else
            {
                //it needs to terminate with the last item
                if ((k+1)==(nums.length-1))
                {
                    end = String.valueOf(nums[k+1]);
                    sm.add(start+"->"+end);
                }
                
                //this is always increased when there are consecutive ascending numbers....
                counter++;
            }            
        }
    
        return sm;
    }
}