L1 · FoundationsList basics~2 min · 4 tests

Separate Even and Odd Numbers

Split a Python list into evens and odds in one pass, keeping the original order, and return both lists as a tuple. Beginner loop practice, tested live.

The problem

Return a tuple (evens, odds) of two lists, each keeping the original order.

Examples

  1. Example 1

    Input

    split_even_odd([1, 2, 3, 4, 5, 6])

    Expected output

    ([2, 4, 6], [1, 3, 5])
  2. Example 2

    Input

    split_even_odd([7, 9])

    Expected output

    ([], [7, 9])

+ 2 hidden tests on Submit.

Edge cases to ask about

  • Zero
  • Negatives
  • Empty

Hints

0/3

    How an interviewer scores this

    0/9
    Python 3.13 · split_even_odd
    ⌘/Ctrl + Enter runs the examples

    Your code runs in real CPython inside your browser — nothing is sent anywhere. The first run downloads the interpreter (about 6 MB, once). Your code is saved on this device as you type.

    Complexity Lab

    What does this cost as n grows?

    Interviewers score the analysis as much as the code. Commit to an answer first — then check it, and measure your code against the optimal one at growing input sizes.

    Time complexity of the optimal solution
    Space complexity (extra memory)

    Pick both to reveal the answer.

    Measure it

    Runs the function on inputs of size 250 up to 16,000 and records the time and peak memory. Slow solutions stop early — a short curve is itself the answer.

    From brute force to optimal

    The progression an interviewer wants to hear, one step at a time.

    ApproachTimeSpaceIdea
    Two comprehensionsO(n)O(n)Two passes.
    bestOne loopO(n)O(n)One pass, two lists.
    Walkthrough of the optimal approach (try it yourself first)

    One loop appending to the right list. Two list comprehensions are equally readable and also O(n) — just two passes instead of one.

    Complexity: O(n) time, O(n) space. One pass; the two output lists together hold n values.

    Reveal the reference solution
    def split_even_odd(nums):
        evens, odds = [], []
        for x in nums:
            (evens if x % 2 == 0 else odds).append(x)
        return evens, odds

    Follow-ups interviewers ask

    • Rearrange in place so evens come first.

    Frequently asked interview questions

    Core interview concepts, complexities, and follow-ups scored by hiring teams.

    What is the time complexity of Separate Even and Odd Numbers in Python?

    The optimal solution runs in O(n) time and O(n) auxiliary space. One pass; the two output lists together hold n values.

    What is the brute-force approach, and how do you optimise it?

    Two comprehensions: O(n) time, O(n) space. Two passes. One loop: O(n) time, O(n) space. One pass, two lists.

    What follow-up questions do interviewers ask about Separate Even and Odd Numbers?

    Rearrange in place so evens come first.