6 kyu

Inverted Ranges

246 of 264wolfendale

Description:

A range of numbers is represented as a tuple of two numbers, for example [0, 10] would indicate a range between 0 and 10 inclusively.

The inverse of a range between some bounds are the ranges from the lower bound, to the lowest part of the range and the upper part of the range to the upper bound.

For example:

  • Given the range [25, 75]
  • And the lower bound 0
  • And the upper bound 100

The inverse ranges would be [[0, 24], [76, 100]].

Write a function invertedRanges which when given a list of ranges, returns the inverse of those ranges with a lower bound of 0 and an upper bound of 100.

All ranges will be between 0 and 100, they will be given in order and will not overlap

Examples:

An empty list of ranges would return a list with a single range between 0 and 100:

invertedRanges([]) == [[0, 100]];
invertedRanges(Nil) == List((0, 100))

A list of ranges which cover numbers between 0 and 100 would return an empty list

invertedRanges([[0, 100]]) == [];
invertedRanges([[0, 50], [51, 100]]) == [];
invertedRanges(List((0, 100))) == Nil
invertedRanges(List((0, 50), (51, 100))) == Nil

A list of ranges which cover some numbers between 0 and 100 must return the ranges that aren't covered

invertedRanges([[0, 25], [51, 75]]) == [[26, 50], [76, 100]];
invertedRanges(List((0, 25), (51, 75))) == List((26, 50), (76, 100))
Algorithms

Stats:

CreatedJun 29, 2021
PublishedJun 29, 2021
Warriors Trained774
Total Skips17
Total Code Submissions1115
Total Times Completed264
JavaScript Completions246
Scala Completions21
Total Stars15
% of votes with a positive feedback rating92% of 63
Total "Very Satisfied" Votes54
Total "Somewhat Satisfied" Votes8
Total "Not Satisfied" Votes1
Total Rank Assessments13
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • wolfendale Avatar
  • zLuki Avatar
  • KayleighWasTaken Avatar
Ad