Sort by several keys in Python, Java, C++ and JavaScript.
Use it when rows have more than one field and ties in the first field need a second rule. Signal words: then by, ties, highest first, a custom order.
Start list the keys from the most to the least important, and say whether each runs up or down.
Step build a key tuple, or write a comparator that tests the first key, and only on a tie the next. Or sort by the minor key first and the major key second, with a stable sort.
Stop when the sort returns. Check the rule on a tie, on an empty list and on the largest values.
It does not help when the keys are small whole numbers and the data is huge: counting sort is faster there.
Cost: O(n log n) comparisons for one sort, and the same for each pass of a multi-pass sort.
In this lesson you sort rows by more than one key, in Python, Java, C++ and JavaScript. You learn how each language states a sort rule, which sorts are stable, and what a comparator must promise. You also see four real failures: a reversed second key, a C++ comparator written with <=, JavaScript's text order for numbers, and an overflow in Java.
You work on a payments app. A payout report lists merchants with the units each one is paid today. The report must show the largest payout first. When two merchants have the same payout, they appear by name, from A to Z.
The report is built in a Python job, a Java service, a C++ batch tool and a JavaScript dashboard. All four must produce the same order.
Your team lead says: Write the sort rule once and use it in all four languages. Tell me how each language says "units high to low, then name A to Z".
Here is a short test: six merchants named mia, kai, zoe, amy, kai and li, paid 50, 90, 50, 90, 70 and 50 units. The right order is amy, kai, kai, li, mia, zoe.
A phone book lists people by surname. When two people share a surname, it lists them by first name. The surname is the major key, and the first name is the minor key.
You look at the surname first. Only when the surnames are equal do you look at the first name. A sort rule with two keys works the same way.
A phone book orders by surname, and only on a tie by first name. A two-key sort works the same way.
Before you write code, order the six payouts by hand. For each row, write its key: the units made negative, and then the name. A smaller key means an earlier row.
Solve it by hand: Six payouts: build the key, then sort. The hand-solve sheet loads in your browser.
Look at amy and kai, who both have 90 units. Their first keys are equal, so the second key decides, and amy comes before kai.
The rows are mia 50, kai 90, zoe 50, amy 90, kai 70 and li 50.
| Row | Name | Units | Key (-units, name) |
|---|---|---|---|
| 0 | mia | 50 | (-50, mia) |
| 1 | kai | 90 | (-90, kai) |
| 2 | zoe | 50 | (-50, zoe) |
| 3 | amy | 90 | (-90, amy) |
| 4 | kai | 70 | (-70, kai) |
| 5 | li | 50 | (-50, li) |
Sorted by key, smallest first: (-90, amy), (-90, kai), (-70, kai), (-50, li), (-50, mia), (-50, zoe). The names read amy, kai, kai, li, mia, zoe.
Start with a correct version. You write the two-key test by hand and sort with insertion: move each row left while the row before it should come after it.
def sort_payouts_by_hand(names, units):
rows = list(zip(names, units))
for i in range(1, len(rows)):
current = rows[i]
j = i - 1
# the row before comes later if it has fewer units, or equal units and a later name
while j >= 0 and (rows[j][1] < current[1] or (rows[j][1] == current[1] and rows[j][0] > current[0])):
rows[j + 1] = rows[j]
j -= 1
rows[j + 1] = current
return [name for name, _ in rows]This is correct. On six rows it is instant.
Now check the real size. The report can hold 100,000 payouts, and the test has to run in four languages.
A run on 5,000 seeded random rows counted the comparisons of each version.
Here is the count:
So the first attempt is correct, but it makes 117 times as many comparisons at 5,000 rows. The fix is not a better loop. It is to give the library sort the rule.
Predict the cost
Q Insertion with a two-key test made 6,432,145 comparisons on 5,000 rows. A library sort with the same rule made 54,864. Roughly how do they compare?
Answer: B
The first count is 6,432,145 and the second is 54,864, a ratio of about 117. Insertion grows with n squared, and a library sort grows with n log n.
The rule is right. What you need is a way to state it to a library sort.
A library sort knows how to order rows. It only needs to learn one thing: which of two rows comes first. You can tell it in two ways.
A key turns each row into a value that sorts the way you want. Python uses a key tuple such as (-units, name). Tuples compare the first item, and then the second only when the first items are equal.
A comparator takes two rows and says which comes first. It returns a negative number when the first row comes first, zero when they tie, and a positive number when the second row comes first.
Both give the same answer. Keys are shorter when each row maps to one value. A comparator is needed when the order depends on both rows together.
Race: Three ways to sort payouts by two keys. The operation counter loads in your browser.
The race counts comparisons by running each version. At 5,000 rows, insertion made 6,432,145 comparisons, one two-key sort made 54,864, and two stable passes made 107,978.
Each row gets a key: minus the units, then the name. Smaller keys come first, and equal units fall back to the name.
There is a second way to use two keys. Sort by the minor key first, which is the name. Then sort by the major key, which is the units. If the second sort is stable, equal units keep the name order from the first pass.
The two passes make about twice as many comparisons as one two-key sort, because each pass sorts all the rows. That is the idea behind the radix sort of the last lesson.
The rows are mia 50, kai 90, zoe 50, amy 90, kai 70 and li 50. Pass 1 sorts by name, and pass 2 sorts by units, high to low. The player stops three times and asks you for a name or a number.
Dry run: Two stable passes: name first, then units. The step-by-step player loads in your browser.
Reading without the player? Cover the last column and predict it row by row.
| After | Rows |
|---|---|
| Input | mia 50, kai 90, zoe 50, amy 90, kai 70, li 50 |
| Pass 1, by name | amy 90, kai 90, kai 70, li 50, mia 50, zoe 50 |
| Pass 2, by units | amy 90, kai 90, kai 70, li 50, mia 50, zoe 50 |
Pass 2 leaves the order as it is. The name order already puts the 90 rows, the 70 row and the 50 rows in the right order. Amy stays before kai because pass 1 put her there.
Predict the order
Q Rows are sorted by name, and then a stable sort by units, high to low, is applied. Amy and kai both have 90 units. Which comes first?
Answer: B
A stable sort keeps rows with equal keys in the order they had before the pass. Pass 1 ordered them by name, so amy stays before kai.
Two ideas now cover every case: a key or comparator that states the order, and a stable sort that lets you split the order into passes.
Here is the rule that keeps a sort rule correct. Every line of the templates exists to protect it.
A comparator must be consistent: it never says a row comes before itself, and it never contradicts its own earlier answers.
A sort assumes that "comes before" behaves like a real order. A row never comes before itself. If a comes before b, then b does not come before a.
If a comes before b and b comes before c, then a comes before c. Rows that tie are interchangeable, and a tie with a third row is the same tie.
That set of rules is called a strict weak ordering. A comparator that breaks it can give different orders for different inputs, loop, or crash.
Use it when rows have more than one field and ties in the first field need a second rule. Signal words: then by, ties, highest first, a custom order.
Start: list the keys from the most to the least important, and say whether each runs up or down.
Step: build a key tuple, or write a comparator that tests the first key, and only on a tie the next. Or sort by the minor key first and the major key second, with a stable sort.
Stop: when the sort returns. Check the rule on a tie, on an empty list and on the largest values.
It does not help when the keys are small whole numbers and the data is huge: counting sort is faster there.
Cost: O(n log n) comparisons for one sort, and the same for each pass of a multi-pass sort.
def sort_payouts(names, units):
# [1] Pair each name with its units, so one row carries both keys.
rows = list(zip(names, units))
# [2] Sort by units from high to low, then by name from A to Z. State the rule once, as a key or a comparator.
rows.sort(key=lambda row: (-row[1], row[0]))
# [3] Return the names in the new order.
return [name for name, _ in rows]public String[] sortPayouts(String[] names, int[] units) {
// [1] Pair each name with its units, so one row carries both keys.
Integer[] rows = new Integer[names.length];
for (int i = 0; i < rows.length; i++) {
rows[i] = i;
}
// [2] Sort by units from high to low, then by name from A to Z. State the rule once, as a key or a comparator.
Arrays.sort(rows, Comparator.comparingInt((Integer i) -> units[i]).reversed().thenComparing(i -> names[i]));
// [3] Return the names in the new order.
String[] result = new String[rows.length];
for (int i = 0; i < rows.length; i++) {
result[i] = names[rows[i]];
}
return result;
}vector<string> sortPayouts(const vector<string>& names, const vector<int>& units) {
// [1] Pair each name with its units, so one row carries both keys.
vector<int> rows(names.size());
iota(rows.begin(), rows.end(), 0);
// [2] Sort by units from high to low, then by name from A to Z. State the rule once, as a key or a comparator.
sort(rows.begin(), rows.end(), [&](int a, int b) {
if (units[a] != units[b]) {
return units[a] > units[b];
}
return names[a] < names[b];
});
// [3] Return the names in the new order.
vector<string> result;
for (int row : rows) {
result.push_back(names[row]);
}
return result;
}function sortPayouts(names, units) {
// [1] Pair each name with its units, so one row carries both keys.
const rows = names.map((_, i) => i);
// [2] Sort by units from high to low, then by name from A to Z. State the rule once, as a key or a comparator.
rows.sort((a, b) => {
if (units[a] !== units[b]) {
return units[b] - units[a];
}
return names[a] < names[b] ? -1 : names[a] > names[b] ? 1 : 0;
});
// [3] Return the names in the new order.
return rows.map((row) => names[row]);
}def sort_payouts_two_pass(names, units):
# [1] Pair each name with its units, so one row carries both keys.
rows = list(zip(names, units))
# [2] First pass: sort by the minor key, the name from A to Z.
rows.sort(key=lambda row: row[0])
# [3] Second pass: a stable sort by the major key, units from high to low. Equal units keep the name order.
rows.sort(key=lambda row: row[1], reverse=True)
# [4] Return the names in the new order.
return [name for name, _ in rows]public String[] sortPayoutsTwoPass(String[] names, int[] units) {
// [1] Pair each name with its units, so one row carries both keys.
Integer[] rows = new Integer[names.length];
for (int i = 0; i < rows.length; i++) {
rows[i] = i;
}
// [2] First pass: sort by the minor key, the name from A to Z.
Arrays.sort(rows, Comparator.comparing((Integer i) -> names[i]));
// [3] Second pass: a stable sort by the major key, units from high to low. Equal units keep the name order.
Arrays.sort(rows, Comparator.comparingInt((Integer i) -> units[i]).reversed());
// [4] Return the names in the new order.
String[] result = new String[rows.length];
for (int i = 0; i < rows.length; i++) {
result[i] = names[rows[i]];
}
return result;
}vector<string> sortPayoutsTwoPass(const vector<string>& names, const vector<int>& units) {
// [1] Pair each name with its units, so one row carries both keys.
vector<int> rows(names.size());
iota(rows.begin(), rows.end(), 0);
// [2] First pass: sort by the minor key, the name from A to Z.
stable_sort(rows.begin(), rows.end(), [&](int a, int b) { return names[a] < names[b]; });
// [3] Second pass: a stable sort by the major key, units from high to low. Equal units keep the name order.
stable_sort(rows.begin(), rows.end(), [&](int a, int b) { return units[a] > units[b]; });
// [4] Return the names in the new order.
vector<string> result;
for (int row : rows) {
result.push_back(names[row]);
}
return result;
}function sortPayoutsTwoPass(names, units) {
// [1] Pair each name with its units, so one row carries both keys.
const rows = names.map((_, i) => i);
// [2] First pass: sort by the minor key, the name from A to Z.
rows.sort((a, b) => (names[a] < names[b] ? -1 : names[a] > names[b] ? 1 : 0));
// [3] Second pass: a stable sort by the major key, units from high to low. Equal units keep the name order.
rows.sort((a, b) => units[b] - units[a]);
// [4] Return the names in the new order.
return rows.map((row) => names[row]);
}Exercise · Break it: Find the rows this two-pass sort misorders. This sorts the payouts in two stable passes: the units first, high to low, and the name second. Find rows where the final order is wrong. The rule is units high to low, then name A to Z.
def sort_payouts_two_pass(names, units):
rows = list(zip(names, units))
rows.sort(key=lambda row: row[1], reverse=True)
rows.sort(key=lambda row: row[0])
return [name for name, _ in rows]Sometimes the order depends on both rows together. To build the largest number from pieces of digits, piece a goes before piece b when the text a + b is larger than b + a. No single key gives that order, so you write a comparator.
from functools import cmp_to_key
def join_largest(parts):
# [1] The comparator puts piece a before piece b when a + b makes the larger text.
def compare(a, b):
if a + b > b + a:
return -1
if a + b < b + a:
return 1
return 0
# [2] Sort the pieces with the comparator.
ordered = sorted(parts, key=cmp_to_key(compare))
# [3] Join the pieces. A leading zero means every piece was zero, so the answer is "0".
joined = "".join(ordered)
return "0" if joined.startswith("0") else joinedpublic String joinLargest(String[] parts) {
// [1] The comparator puts piece a before piece b when a + b makes the larger text.
Comparator<String> byJoin = (a, b) -> (b + a).compareTo(a + b);
// [2] Sort the pieces with the comparator.
String[] ordered = parts.clone();
Arrays.sort(ordered, byJoin);
// [3] Join the pieces. A leading zero means every piece was zero, so the answer is "0".
String joined = String.join("", ordered);
return joined.startsWith("0") ? "0" : joined;
}string joinLargest(const vector<string>& parts) {
// [1] The comparator puts piece a before piece b when a + b makes the larger text.
auto byJoin = [](const string& a, const string& b) { return a + b > b + a; };
// [2] Sort the pieces with the comparator.
vector<string> ordered = parts;
sort(ordered.begin(), ordered.end(), byJoin);
// [3] Join the pieces. A leading zero means every piece was zero, so the answer is "0".
string joined;
for (const string& piece : ordered) {
joined += piece;
}
return (!joined.empty() && joined[0] == '0') ? "0" : joined;
}function joinLargest(parts) {
// [1] The comparator puts piece a before piece b when a + b makes the larger text.
const byJoin = (a, b) => (a + b > b + a ? -1 : a + b < b + a ? 1 : 0);
// [2] Sort the pieces with the comparator.
const ordered = [...parts].sort(byJoin);
// [3] Join the pieces. A leading zero means every piece was zero, so the answer is "0".
const joined = ordered.join("");
return joined.startsWith("0") ? "0" : joined;
}Rebuild the template: put its lines back in order. Loads in your browser.
Exercise · Find the bug: The code that is all zeros. This joins the pieces into the largest number, but for some inputs the answer has leading zeros. Which line is wrong?
from functools import cmp_to_key
def join_largest(parts):
def compare(a, b):
if a + b > b + a:
return -1
if a + b < b + a:
return 1
return 0
ordered = sorted(parts, key=cmp_to_key(compare))
joined = "".join(ordered)
return joinedA comparator must be consistent: a row never comes before itself, and its answers never contradict each other.
The three templates share one question: how do I state which row comes first? You can answer it before you write code.
.reversed() on that key's comparator before thenComparing in Java, flip the test in C++ and swap the operands in JavaScript. A string key cannot be negated: use two stable passes instead.std::stable_sort in C++.Then check the two ends: what does the rule do on a tie, and on an empty list?
| Language | Key or comparator | Stable? |
|---|---|---|
| Python | key=lambda row: (-row[1], row[0]) |
Yes: sort and sorted are guaranteed stable |
| Java | Comparator.comparing(...).thenComparing(...) |
Yes for object sorts such as Arrays.sort(T[], comparator) |
| C++ | a lambda that tests one key, then the next | std::sort is not guaranteed stable; std::stable_sort is |
| JavaScript | (a, b) => number |
Yes: required since ES2019 |
The app joins the pieces 3, 30, 34, 5 and 9 into the largest possible number. Template 3 puts piece a before piece b when a + b is larger than b + a.
| Pair | a + b | b + a | Which first |
|---|---|---|---|
| 3 and 30 | 330 | 303 | 3 |
| 34 and 3 | 343 | 334 | 34 |
| 5 and 34 | 534 | 345 | 5 |
| 9 and 5 | 95 | 59 | 9 |
The sorted pieces are 9, 5, 34, 3, 30. Joined, they read 9534330, and a run of the template returned the same text.
Exercise · Predict the output: What does the comparator join?. The comparator puts piece a before piece b when a + b is larger than b + a, as text. The pieces are 10, 2, 9 and 91. What does the code print?
from functools import cmp_to_key
def compare(a, b):
if a + b > b + a:
return -1
if a + b < b + a:
return 1
return 0
pieces = ["10", "2", "9", "91"]
pieces.sort(key=cmp_to_key(compare))
print("".join(pieces))Real data brings edge cases.
For names = [] or one row, every template returns the list as it is. The sort never calls the comparator.
For names = ["bo", "al", "cy"] with equal units, only the second key matters, and the order is al, bo, cy. When the names are equal too, the rows are identical, so any order of them gives the same output.
For units of 1,000,000,000 and 1,000,000,000 the subtraction in a JavaScript comparator is exact, because numbers are exact up to 2^53. In Java the same subtraction on int values can overflow, so use Integer.compare or Comparator.comparingInt.
In Python, -row[1] works for numbers, but -row[0] on a name raises TypeError: bad operand type for unary -: 'str'. To sort names from Z to A and units from high to low, use two stable passes, or cmp_to_key.
This Python version writes sorted(rows, key=lambda r: (r[1], r[0]), reverse=True). It reverses the whole key, so the names also run from Z to A.
Counterexample: the six payouts come out as kai, amy, kai, zoe, mia, li. The right order is amy, kai, kai, li, mia, zoe. The units are right, but kai comes before amy.
Java has the same trap. comparingInt(units).thenComparing(name).reversed() reverses the whole chain, and a run on the six payouts gave kai, amy, kai, zoe, mia, li. Put .reversed() straight after comparingInt(units), before thenComparing.
Negate the number key, or sort in two stable passes.
This version returns a <= b for the comparator. It says a value comes before an equal value, so it breaks the strict weak ordering that std::sort assumes. The behaviour is undefined.
Counterexample: std::sort on a vector of 100 equal integers with [](int a, int b) { return a <= b; }, compiled with Clang 21 and libc++ at -O2, ended with exit code 138 (a bus error). Because the behaviour is undefined, another compiler or library may crash differently, loop, or give no error at all.
Use < or > only.
A comparator written with less than or equal says a value comes before an equal value. In a test, 100 equal values crashed std::sort.
This version calls .sort() on numbers with no comparator. JavaScript then compares the items as text.
Counterexample: [10, 9, 1, 100].sort() returns [1, 10, 100, 9], and [5, 25, 100, 1].sort() returns [1, 100, 25, 5]. With the comparator (a, b) => a - b, the first list gives [1, 9, 10, 100].
Always pass a comparator for numbers.
This JavaScript version returns a > b. A boolean turns into 1 or 0, and never into a negative number, so the sort cannot tell "before" from "tie".
Counterexample: [3, 1, 2, 5, 4].sort((a, b) => a > b) returned [3, 1, 2, 5, 4] in Node 22: nothing moved.
Return a negative number, zero or a positive number.
This Java version writes (p, q) -> p - q for Integer values. When the difference passes 2,147,483,647, it wraps around.
Counterexample: sorting [2000000000, -2000000000] with that comparator returned [2000000000, -2000000000]. With Integer::compare it returned [-2000000000, 2000000000].
Use Integer.compare or Comparator.comparingInt.
A game says rock beats scissors, scissors beats paper, and paper beats rock. No sort order fits, because the comparison goes in a circle.
Run: Python's sorted with this comparator returned ['s', 'p', 'r'] for the input r, p, s but ['r', 's', 'p'] for the input r, s, p. The result depends on the input order, so it is not a sort.
A comparator needs a strict weak ordering. Without one, use a different method.
The guarantees differ by language, so state them with care.
list.sort and sorted are documented as stable.Arrays.sort(T[], comparator) and List.sort, are documented as stable. Sorts of int[] have no stability question, because equal ints cannot be told apart.std::sort is not required to be stable, and what it does depends on the library. The test used 1,000 records with keys 0 to 4 from std::mt19937, seed 1. With libc++, std::sort left 505 adjacent equal-key pairs out of input order, and std::stable_sort left 0. On 10 records, std::sort happened to keep the order.Array.prototype.sort has been required to be stable since the 2019 edition of the standard.Your team lead brings four product changes. Each one asks for a different rule.
The report must list some merchants in a fixed order and the rest by name. Map each merchant to its place in the list, or to a large number if it is missing. Then sort by that key and by name. The problem "Relative order of a priority list" practises it.
Permission masks must be ordered by how many bits are set, and then by value. That is a key tuple with a computed first key. LeetCode 1356: Sort Integers by The Number of 1 Bits is the same task.
Pieces of a code must be joined into the largest number. That needs the custom comparator of Template 3. This is LeetCode 179: Largest Number, and the problem "Largest number from the pieces" practises it.
Bikes on a one-lane road must be grouped into convoys. Sort the bikes by position, then scan from the end of the road. The problem "Bike convoys on a one-lane road" is LeetCode 853: Car Fleet.
Explain it back: write the idea in your own words and get feedback.
In two or three sentences, explain to a teammate how you sort rows by two keys in your favourite language. Then say what a comparator must promise. The AI tutor checks your answer against the invariant and the key points of this lesson.
Here is how you could explain it in an interview, now that you have run it.
I list the keys from most to least important and state each direction. Python uses a key tuple, Java chains comparing and thenComparing, C++ uses a lambda, and JavaScript returns a number. The comparator must be consistent, so a row never comes before itself.
To sort by two keys, I list them from the most to the least important and say whether each goes up or down. In Python I use a key tuple, with a minus sign on a number that runs high to low.
In Java I chain Comparator.comparing with thenComparing. In C++ I write a lambda that tests the first key and, only on a tie, the second. In JavaScript the comparator returns a negative number, zero or a positive number, never a boolean.
The rule must be a strict weak ordering. A row never comes before itself, so in C++ I use less than, never less than or equal. Breaking the rule is undefined behaviour, and a test with 100 equal values crashed.
Python, JavaScript and Java object sorts are stable. C++ std::sort is not guaranteed stable, so I use std::stable_sort when ties must keep their order. A stable sort also lets me sort by the minor key first and the major key second.
Checkpoint · Comparators in four languages
Q1/10 In Python, how do you sort rows by units from high to low, then by name from A to Z?
Answer: B
The minus sign flips only the first key. Reversing the whole key also reverses the names, and the lesson's run gave kai before amy.
Q2/10 Which Java expression states "units high to low, then name A to Z" for row positions?
Answer: B
comparingInt orders by units, reversed() flips it to high to low, and thenComparing breaks ties by name. reversed() flips the whole chain before it, so placed last it would flip the names too.
Q3/10 In a C++ comparator lambda for two rows, what is the right way to break a tie on the first key?
Answer: B
A comparator tests the first key, and only when the keys are equal it tests the next. It uses strict < or >, never <= or >=.
Q4/10 A JavaScript comparator is called with two rows. What must it return?
Answer: B
The sort needs a sign. A boolean becomes 1 or 0 and never negative, and the lesson's run of (a, b) => a > b left [3, 1, 2, 5, 4] unchanged.
Q5/10 What does [10, 9, 1, 100].sort() return in JavaScript?
Answer: C
With no comparator, JavaScript compares the items as text, so "10" comes before "9". The lesson's run printed [1, 10, 100, 9].
Q6/10 A C++ comparator is written as [](int a, int b) { return a <= b; }. What is true?
Answer: C
The comparator says a value comes before an equal value. In one test, 100 equal values ended with exit code 138, and another compiler may behave differently.
Q7/10 Which statement about stability is accurate?
Answer: C
Python, Java object sorts and JavaScript (since 2019) are stable, and C++ has std::stable_sort. std::sort is not required to be stable.
Q8/10 You sort rows by name, then by units from high to low with a stable sort. Two rows have equal units. Which comes first?
Answer: B
A stable pass keeps rows with equal keys in the order they had. The first pass sorted by name, so the earlier name stays first.
Q9/10 Why does key=lambda r: (-r[0], r[1]) fail when r[0] is a name?
Answer: B
The lesson's run raised TypeError: bad operand type for unary -: 'str'. Use two stable passes or cmp_to_key for a string key that must run downwards.
Q10/10 Rock beats scissors, scissors beats paper, paper beats rock. What happens if you sort with that comparator?
Answer: C
The lesson's run returned s, p, r for one input order and r, s, p for another. A comparator must be a strict weak ordering.
Ten questions on this lesson. Pass with 80% or more to be sure the idea has landed before the next lesson.
| Step | Problem | Product line | Level | What it practises |
|---|---|---|---|---|
| 1 | Sort by two keys in four languages | Pay | Easy | A key or comparator with a tie rule |
| 2 | Relative order of a priority list | Chat | Easy | A computed key, then a tie rule |
| 3 | Sort by number of set bits | Platform | Easy | A key tuple with a computed first key |
| 4 | Largest number from the pieces | Pay | Medium | A comparator that is not a key |
| 5 | Bike convoys on a one-lane road | Freight | Medium | Sort by position, then scan |
Review cards from this lesson.
Step through the idea on your own input, then build it in the lab. Runs in your browser. Step through it.
A few questions, then explain the idea back in your own words. Your tutor marks it. Quiz and explain back.