Three easy problems the way an online assessment frames them: letters to count, a runner-up with ties, and words to mirror. A 40-minute round with a plan.
Service companies and mass recruiters hire freshers in large batches, often thousands in one season. The first filter is almost always an online assessment: a timed test with two or three coding problems, opened in a browser, with no interviewer. A grader runs your code against hidden tests and gives a score. You never get to explain your thinking, so the code has to speak for itself.
That changes what matters, and four habits earn most of the marks.
This is encouraging news. The patterns are few, you have already met them in the Academy, and a round of practice makes them automatic. The warm-up round tests three of them on easy problems, and it is the first of three rounds in the set. The core and stretch rounds that follow use the same habits on classics with one twist.
Exercise · Predict the output: Runner-up with a tie. Four posts have 4, 9, 9 and 2 likes. Equal counts take separate places, so two posts with 9 likes hold places one and two. What does this print?
likes = [4, 9, 9, 2]
best = -1
second = -1
for count in likes:
if count > best:
second = best
best = count
elif count > second:
second = count
print(second)Each problem is easy because it needs one idea you already know. The skill an assessment adds is spotting the idea under the story and the trap hidden in one sentence.
| Signal in the statement | The move | Academy lesson |
|---|---|---|
| count vowels and consonants, ignore the rest | one pass with two counters, after the case and the letter test | Strings and builders |
| the second place, equal counts allowed | two running values, best and second | Traversal and in-place edits |
| mirror every word, keep the spaces | two pointers inside each word, on a mutable copy | Strings and builders |
Look for the trap in each statement. In the first, capitals count the same as small letters, digits and punctuation are not letters, and y is a consonant. Lower the character once, test the range a to z, and only then test the vowels.
In the second, the statement decides whether equal values share a place. Here they do, so a value equal to the best must still be allowed to take second place. The distinct version of this problem is common, and the two look the same until a test has a tie.
Exercise · Find the bug: Runner-up that skips ties. This returns the like count in second place, where equal counts hold separate places. It is right when the top count is unique, but wrong when two posts share it. Which line is wrong?
def second_largest(likes):
best = -1
second = -1
for count in likes:
if count > best:
second = best
best = count
elif count > second and count < best:
second = count
return secondA value equal to the best takes second place when equal counts hold separate places.
Mirroring the words has a different trap. A short solution splits the caption on spaces, reverses each piece and joins them with one space. It passes the sample and loses every run of spaces. Hidden tests nearly always include a caption with two spaces in a row, or a space at the end.
Exercise · Break it: Mirrored words that lose spaces. This mirrors each word of a caption by splitting it into words and joining them with one space. Find captions where the result differs from the right answer, which keeps every space where it was.
def mirror_words(caption):
words = caption.split()
out = []
for word in words:
out.append(word[::-1])
return " ".join(out)Splitting and joining loses spaces; swapping inside a copy of the characters keeps them.
All three problems are easy, and together they make one warm-up round. Each time box is a little generous, because in an assessment you also read the statement and test the sample.
Solve them in this order. The letter counts are one pass, the runner-up adds the tie rule, and the mirrored words add pointers inside a copy.
When your code passes, change one rule and ask what changes. These are the variations that assessments reuse in later questions.
Treat the three problems as one assessment: 40 minutes in all, with a timer, in the language you plan to use on the day. Nobody is watching, so build the habits that a grader rewards.
Write down how long each problem took. The trend across several rounds matters more than any one score, and it shows which pattern to practise next.
Checkpoint · Mass-recruiter warm-up round
Q1/5 What is the best use of the first minute of an online assessment problem?
Answer: B
A hidden test can check any sentence of the statement. A minute spent listing the rules saves far more minutes of debugging.
Q2/5 The query is "Sky 2 Fly!". How many vowels and consonants does it have, with y as a consonant?
Answer: B
The letters are s, k, y, f, l and y, so there are six consonants and no vowel. The digit, the spaces and the mark are not letters.
Q3/5 Four posts have 4, 9, 9 and 2 likes, and equal counts hold separate places. What is the like count in second place?
Answer: B
The two posts with 9 likes hold places one and two. Ignoring a value equal to the best gives 4, which solves the distinct version.
Q4/5 A caption is "a bc", with two spaces. Which approach keeps both spaces when it mirrors each word?
Answer: B
Joining with one space drops the extra space. Swapping characters inside each word of a copy never moves a space.
Q5/5 The set has three problems and 40 minutes. What is a sound plan for the clock?
Answer: B
A score is the share of tests that pass across all problems. Time boxes make sure every problem gets a working answer.
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.