Skip to the content

Do the two times overlap?

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):
    pass

JavaScript

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

See all challenges →