Do the two times overlap?
- O(1) · Trivial
- Free
- Python
- JavaScript
- conditionals
- booleans
- comparisons
Problem
Two classes want the same room: the first one runs from hour a1 to a2, the second from b1 to b2. Write a function that returns true when the two overlap at any point.
If one ends at the exact hour the other starts they don't overlap, so both fit. And they arrive in no order: the second one may start first.
Examples
Half on top of each other
9, 11, 10, 12 → true
One after the other
9, 10, 11, 12 → false
The second fits inside the first
9, 12, 10, 11 → true
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def overlaps(a1, a2, b1, b2):
passJavaScript
function overlaps(a1, a2, b1, b2) {
}Solve this challenge
It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.
More O(1) challenges
- Does it fall in range?conditionals · booleans · comparisons
- Does the photo fit the envelope?lists · conditionals · booleans
- How far apartoperations · comparisons
- How far from free shippingoperations · conditionals
- How far off is it?conditionals · comparisons · operations
- How many blocks you walklists · indexes · operations