Three classics in disguise, the way an online assessment frames them: titles that share letters, a missing marker, and a picture turned many times. A 45-minute round.
The middle problems of an online assessment at a service company or mass recruiter are usually the classics. You have seen them in books and courses: two strings that are anagrams, the missing number in a sequence, a grid to rotate. The test writer wraps each one in a small story and adds one twist, so that a copied solution fails a hidden test.
That gives you a clear job with two steps.
A score is the share of tests that pass. A classic with the wrong twist still earns some marks, and a classic with the right twist earns them all. You need to be careful more than clever. Each time you meet a new statement, write the classic and the twist as two short lines before you type any code.
This is the second of three rounds in the set. It has two easy problems and one medium problem, which is the usual mix in the middle of a test.
Exercise · Predict the output: Counters that do not return to zero. Two titles are compared with 26 counters: each letter of the first adds one, and each letter of the second takes one away. How many counters are not zero at the end?
first = "Dormitory"
second = "Dirty rooms"
counts = [0] * 26
for ch in first.lower():
if "a" <= ch <= "z":
counts[ord(ch) - ord("a")] += 1
for ch in second.lower():
if "a" <= ch <= "z":
counts[ord(ch) - ord("a")] -= 1
leftover = 0
for c in counts:
if c != 0:
leftover += 1
print(leftover)Each problem below names its classic in the statement if you read for the signal. The Academy lessons give the method, so this round is about the twist.
| Signal in the statement | The move | Academy lesson |
|---|---|---|
| the same letters in any order, other characters ignored | 26 counters: add for one title, subtract for the other | Frequency, palindromes and anagrams |
| one value missing from an equally spaced run | the expected sum, minus the sum of what is present | Bits and maths basics |
| a grid turned and flipped by a long list of presses | fold the presses into a turn count and one flip, then draw once | Traversal and in-place edits |
The missing marker is the textbook missing number with a twist: the road does not start at 1, and the step is not 1. The expected sum comes from the first marker, the last marker and how many markers the full road had. The full road has one more marker than the list, and that extra one is the easiest thing to forget.
Exercise · Find the bug: The road has one more marker. This returns the missing marker of an equally spaced road, given the markers that survive. It is close but never right. Which line is wrong?
def missing_marker(markers):
n = len(markers)
expected = (markers[0] + markers[-1]) * n // 2
present = 0
for value in markers:
present += value
return expected - presentThe full road has one more marker than the list, so the expected sum uses the count plus one.
The edited thumbnail is the medium problem, and it is where careful reading pays. Each press either adds a quarter turn or flips the picture. A flip changes the direction of every earlier turn, so the code keeps a turn count and a flip flag, and applies each once at the end.
Exercise · Predict the output: Folding the presses. Presses are folded into a turn count (0 to 3) and a flip flag. R adds a turn. H flips and reverses the direction of the turns so far. For the presses R, H, R, R, what does this print? The number is the turn count times 10 plus the flag.
ops = "RHRR"
turns = 0
flipped = 0
for op in ops:
if op == "R":
turns = (turns + 1) % 4
else:
turns = (4 - turns) % 4
flipped = 1 - flipped
print(turns * 10 + flipped)A flip reverses the direction of the earlier turns, so the turn count must change at the flip.
The titles problem has its own small trap, which is why the counters must all return to zero. A total of zero is not enough. A plus one on one letter and a minus one on another cancel out, and the two titles are not anagrams. Test each counter on its own.
Two easy problems and one medium make a realistic middle section. Give the easy ones their full time box, and do not let them spill into the medium one.
Solve them in this order. The anagram is a counting pass, the missing marker is one formula, and the thumbnail is the first problem where the shape of the data changes.
Assessments often reuse a classic with one rule changed, so prepare one change for each problem.
Treat the three problems as one section of a test: 45 minutes in all, with a timer.
The classic plus the twist is the whole skill. If you can say both in two sentences, the code is usually short.
Checkpoint · Mass-recruiter core round
Q1/5 What are the two steps for an assessment problem that wraps a classic in a story?
Answer: B
The classic gives the method and the twist gives the edge cases. Together they describe the whole problem in two sentences.
Q2/5 Two titles are compared with 26 counters, one up and one down. When are they anagrams?
Answer: C
A total of zero can hide a plus one and a minus one on two different letters. Every counter must return to zero.
Q3/5 The markers 4, 9, 14 and 24 survive on an equally spaced road. How many markers did the full road have?
Answer: B
The step is 5, and the full road is 4, 9, 14, 19 and 24, so it had 5 markers. The missing one is 19.
Q4/5 A road has first marker 4, last marker 24 and 5 markers on the full road. What is the sum of the full road?
Answer: B
The sum is (4 + 24) times 5, divided by 2, which is 70. The surviving markers add to 51, so the missing marker is 19.
Q5/5 The presses are R, H, R, R. Which pair of values does the folding rule give for turns and flip?
Answer: B
The flip reverses the direction of the turn already made, so the count goes from 1 to 3, then to 0 and 1 with the last two R presses. The flag is set once.
Review cards from this lesson.
A few questions, then explain the idea back in your own words. Your tutor marks it. Quiz and explain back.