Mobile, performance and coding · core
Coding problems testers get asked
Testers get small coding tasks: count characters, find the second largest, find pairs, read a CSV, check links. Say the cost, handle edge cases and test your code.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Count characters: loop over the lower-cased characters, skip whitespace, and use map.merge(c, 1, Integer::sum) in a LinkedHashMap (it keeps first-seen order). O(n) time, O(k) space for k distinct characters.
- First non-repeating character: the first entry with count 1 in a LinkedHashMap. A HashMap does not keep order.
- Unicode: a Java char is one UTF-16 unit. Emoji need code points (codePoints()).
- Second largest without sorting: keep first and second, start them as "not set" (not 0), update in one pass. Skip equal values for a distinct answer. [5, 5, 5] has no second largest, so return empty or throw a clear exception. O(n) time, O(1) space.
- Arrays.sort then arr[n - 2] is wrong with duplicates.
- Pairs that add up to a target: keep a set of numbers seen; for each n check target - n; store pairs in a set to remove repeats. O(n) time and space. [4, 4] with target 8 is valid only because 4 appears twice.
- Read a CSV from the classpath with try-with-resources and UTF-8, map header names, skip blank lines, return a list of records. split(",") breaks on quoted commas; use a CSV library for real data.
- Broken links: collect hrefs, remove duplicates, skip mailto, tel, javascript and # anchors, check with HttpClient using HEAD and a timeout (fall back to GET on 405), limit parallel calls, follow redirects, and report the URL with its status.
- Always say the time and space cost out loud, give edge cases, and write tests.
The red pen
Common traps: mistake → fix
Mistake: Nested loops are fine for counting
Fix: say the O(n^2) cost and use a map.
Mistake: Start the maximum at 0
Fix: it fails when all numbers are negative.
Mistake: A 3xx response is a broken link
Fix: a redirect is not broken.
Mistake: Reading the file again for every test is fine
Fix: read once and reuse.
Easy to hard
Questions interviewers ask, easy to hard
- Count each character in a string.
- Find the second largest number without sorting.
- Find all pairs that add up to a target.
- Read test data from a CSV file for a DataProvider.
- How would you find broken links on a page?
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.