← Back to challenges

Opposite House 🏘️

PythonHardmathnumberslogicinterview

Instructions

Mubashir was walking through a straight street with exactly n identical houses on both sides. House numbers in the street look like this:

1 |   | 6

3 |   | 4

5 |   | 2

He noticed that Even numbered houses increase on the right while Odd numbered houses decrease on the left.

Create a function that takes a house number house and length of the street n and returns the house number on the opposite side.

Examples

opposite_house(1, 3) ➞ 6

opposite_house(2, 3) ➞ 5

opposite_house(3, 5) ➞ 8

Notes

N/A

python3
Loading editor…
⌘ ↡ to run
Walks through the solution with reasoning and edge cases.
Next: Running Athlete πŸƒ β†’