Skip to the content

Does the photo fit the envelope?

Problem

You get a photo and an envelope, each one as a list of two measurements in centimeters: the width first, the height after.

The photo fits if both of its sides fit inside the envelope, and you may turn it a quarter turn: a photo of 20 by 10 fits in an envelope of 12 by 20, lying sideways. Return true if it fits and false if it doesn't.

A photo exactly as big as the envelope fits. Every measurement is positive and each list always has two.

Examples

  • Fits as it comes

    [10, 15], [12, 20] → true

  • Fits turned around

    [20, 10], [12, 20] → true

  • Fits no way at all

    [15, 15], [12, 20] → false

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def fits(pic, envelope):
    pass

JavaScript

function fits(pic, envelope) {
}
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 →