Ruby O(n) Time O(n) space


#1
        hash = Hash.new
        
        a.each do |item|
            hash[item] = item
        end
        
        max = 0
        i = 0
        temp = a[i]
        
        while (i < a.length)
            
            temp_max = 0
            
            decr = temp - 1
            while hash.has_key?(temp)
                temp_max+= 1
                hash.delete(temp)
                temp+= 1
            end
            
            while hash.has_key?(decr)
                temp_max+= 1
                hash.delete(decr)
                decr-= 1
            end
            
            
            i+= 1
            
            max = temp_max if max <= temp_max
            temp_max = 0
            
            temp = a[i]
            
        end
        
        max