Embercode
✕
Linked ListsQuick quiz

Palindrome and partition in Python

7 questions. Covers Partition and odd-even reordering in Python.

Questions 1 to 5 of 7

  1. 1. Put the four steps of the palindrome check in the order the lesson runs them.

    Use the arrows to put the steps in order.

    1. 1.Compare the first half with the reversed second half, pair by pair
    2. 2.Reverse the second half again to restore the list
    3. 3.Reverse the second half, starting at the slow pointer
    4. 4.Find the middle with a slow pointer and a fast pointer
  2. 2. Why must the restore step (reversing the second half again) run even when the comparison has already found a mismatch?
  3. 3. Using is_palindrome, build and show from the palindrome lesson, what does this code print? ``python h = build([4, 5, 4, 5]) print(is_palindrome(h), show(h)) ``
  4. 4. In split, the line nxt = cur.next comes before yes.add(cur). Why does it have to come first?
  5. 5. Using partition from this lesson, with build and show from the palindrome lesson, what does this code print? ``python h = build([3, 1, 4, 1, 5]) print(show(partition(h, 4))) ``

4 question(s) left on this page.