https://leetcode.com/problems/summary-ranges/description/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    vector<string> summaryRanges(vector<int>& nums) {
        int n = nums.size();
        vector<string> ans;
        int idx = 0;
        while (idx < n) {
            int start = nums[idx];
            while (idx + 1 < n && nums[idx] + 1 == nums[idx + 1]) idx += 1;
            if (start == nums[idx]) ans.push_back(to_string(start));
            else ans.push_back(to_string(start) + "->" + to_string(nums[idx]));
            idx += 1;
        }
        return ans;
    }
};

Time Complexity: O(n)
Space: O(n)