Skip to content
CodeItRaw
Arrays

Lesson 3/6

Some questions look not at one element but at two side by side: is it sorted, is it rising, does the same value repeat. For that it is enough to remember the one before as you go.

for i in range(1, len(values)):
if values[i - 1] > values[i]:
return False
return True
The loop starts at 1 because the first element has nothing before it. A list of n elements has n − 1 neighbouring pairs; the loop must look at all of them, the last included.

Finding the longest run of the same value is neighbour work too: if the element equals the one before, lengthen the run by one; if not, start the run again at 1; remember the longest at every step.

Tasks

Tasks open in order. Solve them all and the next lesson opens.

This lesson's tasks open when the lessons before it are finished. You can read the explanation now.Go to the current lesson

  1. 01

    Order Check

    Function

  2. 02

    Is It Sorted?

    Code reading · Break the Code

  3. 03

    Log Streaks

    Function

If you would rather not wait for the order, every problem is open without locks: Problem list