Professional Documents
Culture Documents
Vipin - Kumar - Set B - Thinkbridge
Vipin - Kumar - Set B - Thinkbridge
Problem Statement
Problem Understanding
Algorithm
for(int i=0;i<n-1;i++){
if(arr[i]<arr[i+1] && abs(arr[i+1]-arr[i]==1))
cnt++;
}
-> we will cnt variable which will be having the count of
consecutive integers.
code output
Problem Understanding
Algorithm
-> we will compare the end time of first index with its
next index's start point
-> if it is greater or equal to the it and also it greater
then or equal to end point
of the its next index then we will take its ending
point and will create an new
updated time stamps.
-> we create an answer array to store new intervals.
-> we are also comparing the end point of next index from
start index's end point
in order to tackle an edge case, for example =
let an intervals are (15,19) and (17,18)
here if we don't comapre the end
point
of next index also then we will an error
-> we will return the ans array or vector.
-> Here we will compare the end time of index with its next
interval's start and end time.
-> we will inser them the updated
interval in our ans vector as ans.push_back({start,end})
-> After loop's termination we will return our ans vector.
Code Output
Problem statement
Problem understanding
Code output