1
// Time Complexity : O(N)2
// Space Complexity : O(1)3
var summaryRanges = function (nums) {4
// Create a list of string to store the output result...6
// Start traversing the array from idx = 0 till idx < sizeofarray in a while loop.8
while (idx < nums.length) {9
// Initialize beg and last index for identifying the continuous element in the array...11
// Mark the number at current index as beginning element of the range...13
// Traverse the array beggining from current index & find the last element whose difference from previous element is exactly 1, i.e. nums[idx + 1] == nums[idx] + 1...14
while (idx + 1 < nums.length && nums[idx + 1] == nums[idx] + 1) idx++;15
// Set this element as last element of the range...17
// If continuous element isn't present...18
if (beg == last) output.push(beg + "");20
else output.push(beg + "->" + last);23
return output; // Return the output result list...