Fall 2025 Thursday, September 25, 2025
Solutions last updated: 9/26/25
Print Your Name:
Print Your Student ID:
Print Student name to your left:
Print Student name to your right:
You have 110 minutes. There are 8 questions of varying credit. (100 points total)
Question: 1 2 3 4 5 6 7 8 Total
Points: 12 6 10 12 10 16 20 14 100
For questions with circular bubbles, select only For questions with square boxes, you may select
one choice (there is only one correct answer). one or more choices (select all that apply).
Unselected option (completely unfilled) You can select
Don’t do this (it will be graded as incorrect) multiple squares
Only one selected option (completely filled) Don’t do this (it will be graded as incorrect)
• Anything you write outside the answer boxes or you cross out will not be graded. If you write multiple
answers or your answer is ambiguous, we will grade the worst interpretation.
• Unless otherwise specified, all data structures and algorithms behave according to their implementation
in lecture, with no additional optimizations.
• If an implementation detail (e.g. tiebreaking scheme, linked list topology) is relevant, it will be explicitly
noted in the question.
• You may write at most one statement per blank and you may not use more blanks than provided.
• Your answer will be reformatted according to the 61B/61BL style guidelines. For example, any method,
constructor, or if-statement requires at least three lines for the purposes of determining line count.
• You may not use ternary operators, lambdas, streams, or multiple assignment.
• Unless otherwise specified, you may assume that everything on the reference card has been imported.
Read the honor code below and sign your name.
By signing below, I affirm that all work on this exam is my own work. I have not referenced any
disallowed materials, nor collaborated with anyone else on this exam. I understand that if I cheat on
the exam, I may face the penalty of an “F” grade and a referral to the Center for Student Conduct.
Page 1 of 15
, Sign your name:
Q1 Map (12 points)
Fill in rankedAbove, which takes in a list of Players and returns a map from each Player to their rank.
The player with the highest score has rank 1, the player with the next-highest score has rank 2, and so on.
For example, if we have a list of players with scores of 500, 800, 1200, and 100, then these players would
have ranks 3, 2, 1, and 4, respectively, and rankedAbove would return the following Map:
{ Player with score 500 : 3,
Player with score 800 : 2,
Player with score 1200 : 1,
Player with score 100 : 4 }
Assume no two players have the same score.
You may not need all lines. Do not worry about efficiency.
public class Player {
public double score;
public static Map<Player, Integer> rankedAbove(List<Player> players) {
Map<Player, Integer> results = new HashMap<>(); ;
for (Player p1 : players ) {
results.put(p1, 1);
for (Player p2 : players) {
if (p2.score > p1.score) {
results.put(p1, results.get(p1) + 1);
}
}
UNUSED
}
return results;
}
}
Page 2 of 15