Move on, but submit first
Three published rules shape how you work on a question:
- You can submit as many times as you like, and your best-scoring submission is the one that counts. A later, worse attempt does not replace it.
- You must submit before leaving a question. Code you wrote and never submitted is not a submission.
- You can move on when stuck, because all four questions stay open and you choose the order.
Those rules suggest a routine. Submit as soon as you have something that runs, then improve it and submit again. When you stop making progress, submit what you have, go to another question, and come back if time remains.
The test also has a History tab, where you can look back at your submissions.
In the visual, watch kept: a worse submission leaves it alone.
See it run
kept = 0 kept = max(kept, 60) kept = max(kept, 90) kept = max(kept, 40) print(kept)
Three submissions to one question. These scores are made up to show the rule: the best one counts.
Practice move on, but submit first
Exercise 1
scores lists the score of each submission to one question, in the order you made them. Submissions are numbered from 1.
Return the number of the submission that counts: the one with the highest score.
Rules:
- If several share the highest score, return the earliest of them.
- Empty
scoresgives0, since nothing was submitted.
Constraints: 0 ≤ len(scores) ≤ 1000; 0 ≤ scores[i] ≤ 1000.
Example: solution([40, 90, 60, 90]) returns 2: the score of 90 first appears on submission 2.
Exercise 2
log lists submissions as [question, score] pairs, in the order they happened.
Return a dictionary mapping each question that appears in log to its best score.
Rules:
- A question appears in the answer if it has at least one submission, even when its best score is 0.
- Empty
loggives{}.
Constraints: 0 ≤ len(log) ≤ 1000; questions are non-empty strings; 0 ≤ score ≤ 1000.
Example: solution([["q1", 40], ["q2", 70], ["q1", 90], ["q1", 60]]) returns {"q1": 90, "q2": 70}.
Exercise 3
events records what you did during a test, as strings:
"edit N": you changed the code of question N."submit N": you submitted question N, so all its changes so far are submitted."open N": you moved to question N. Moving does not submit anything.
Return a list of the question numbers, as integers from smallest to largest, that still have unsubmitted changes at the end.
Rules:
- Empty
eventsgives[]. - Submitting a question with no changes does nothing.
Constraints: 0 ≤ len(events) ≤ 1000; 1 ≤ N ≤ 4.
Example: solution(["edit 1", "open 2", "edit 2", "submit 2"]) returns [1]: question 1 was left without a submit.
The explanation and tasks are public. Running this lesson requires an account with course access.
Practice
Loading Python…Visualizer Watch your code run line by line
Run your code, then choose Play to follow its execution.