How do you calculate total duration of overlapping time-spans
How do you calculate total duration of overlapping time-spans This code is good for a set of times sorted in ascending order only! I was getting the wrong answer because the original set of times were given and expected to be calculated unsorted I'm trying to write a piece of code that will calculate the total duration of a given set of task times, where w tasks can be worked on at any given time. If there are two tasks going on, and one of them finish, then another will start immediately. To give some context, the times are in a sorted array as below; int times = {2,2,3,4}; //short array for example int n = sizeof(times) / sizeof(times[0]); int w = 2; //number of tasks that can be done simultatenously int total_time = 0; The method I'm going with is to sum all the wth times in the array. So in this example,the total time should be the second and fourth values (2+4).For that I run a for loop. int main() { for (int i = n-1; i >= 0; i -= w) { //std::cout ...
