7 kyu

How many days are we represented in a foreign country?

882 of 2,272JorgeVS

Description:

How many days are we represented in a foreign country?

My colleagues make business trips to a foreign country. We must find the number of days our company is represented in a country. Every day that one or more colleagues are present in the country is a day that the company is represented. A single day cannot count for more than one day.

Write a function that recieves a list of pairs and returns the number of days that the company is represented in the foreign country. The first number of the pair is the number of the day of arrival and the second number of the pair is the day of departure of someone who travels, i.e. 1 january is number 1 and 31 of december is 365.

Example:

days_represented(2, {{10, 17}, {200, 207}});
daysRepresented [(10,17),(200,207)]
daysRepresented (new int[][] {{10,17},{200,207}}) 
daysRepresented ([[10,17],[200,207]])
days_represented([[10,17],[200,207]])

Returns 16 because there are two trips of 8 days, which add up to 16.

Happy coding and rank this kata if you wish ;-)

Lists
Fundamentals

More By Author:

Check out these other kata created by JorgeVS

Stats:

CreatedApr 8, 2017
PublishedApr 8, 2017
Warriors Trained5553
Total Skips149
Total Code Submissions21921
Total Times Completed2272
Haskell Completions83
Java Completions383
JavaScript Completions865
Python Completions882
C Completions66
Rust Completions62
Nim Completions9
Total Stars59
% of votes with a positive feedback rating87% of 521
Total "Very Satisfied" Votes418
Total "Somewhat Satisfied" Votes74
Total "Not Satisfied" Votes29
Total Rank Assessments10
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • JorgeVS Avatar
  • smile67 Avatar
  • imjasonmiller Avatar
  • Voile Avatar
  • rowcased Avatar
  • metagn Avatar
  • hobovsky Avatar
  • username0 Avatar
  • user8436785 Avatar
Ad