Knowing that Vector startpoints is the start of snowy road a
Knowing that Vector start_points is the start of snowy road and Vector end_points is the end of the snowy patch of road, return the total length of highway segments covered by snow.
Note that the reported segments may overlap.
My code does not deal with the problem of start and end points that are within other start or end points (overlap, which creates a longer length than there actually is).
my code (bolded code is part of the question and cannot be changed):
int snowy_highway_length(Vector &start_points, Vector &end_points) {
// fill in code here
int length = 0;
for (int i = 0; i < start_points.size(); i++){
length = length + (end_points[i] - start_points[i]);
}
return length;
}
Solution
int snowy_highway_length(Vector &start_points, Vector &end_points) {
// fill in code here
int length = 0;
for (int i = 0; i < start_points.size(); i++){
if ((end_points[i] - start_points[i]) <= 0)
break;
length = length + (end_points[i] - start_points[i]);
}
return length;
}
