← Back to challenges

Left Side, Right Side

PythonHardarraysloops

Instructions

Create two functions:

  1. Leftside function: Returns count of numbers strictly smaller than n on the left.
  2. Rightside function: Returns count of numbers strictly smaller than n on the right.

Examples

left_side([5, 2, 1, 4, 8, 7]) ➞ [0, 0, 0, 2, 4, 4]

right_side([5, 2, 1, 4, 8, 7]) ➞ [3, 1, 0, 0, 1, 0]

left_side([1, 2, 3, -1]) ➞ [0, 1, 2, 0]

right_side([1, 2, 3, -1]) ➞ [1, 1, 1, 0]

Notes

"Left" and "right" refer to the number at indices less than or greater than n's index, respectively.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.