Implement uniq: Unique Lines
Reported by candidates from Vanta's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Vanta reported this OA in September 2026, and the detail that catches people is the follow-up about files too large for memory. The base task is a uniq-style function: given an array of lines, return only the first occurrence of each distinct line, in original order. Empty strings count as lines and comparison is case-sensitive. It's a hash-set problem that looks too easy, which is exactly why people rush it and miss an edge case. If you blank on the live OA, StealthCoder runs invisibly on your desktop and gives you the solution in real time.
The problem
You are implementing the core behavior of a uniq-style command. Given the lines of a file in order, return only the first occurrence of each distinct line while preserving the original order of first appearance. The interview follow-up may ask how to handle files too large to fit in memory. For this function, implement the in-memory version over the provided array of lines. Function getUniqueLines(lines: String[]) → String[] Examples Example 1 lines = ["apple", "banana", "apple", "carrot", "banana"] return = ["apple", "banana", "carrot"] Only the first occurrence of each distinct line is kept. Example 2 lines = ["", "x", "", "X"] return = ["", "x", "X"] Empty strings are valid lines, and comparison is case-sensitive. Constraints Preserve the order of first appearance. Line comparison is exact and case-sensitive. The base function may use memory proportional to the number of distinct lines.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is one pass with a hash set. Walk the array, check whether the line is already in the set, and if not, add it to the set and append it to the result. That's O(n) time and O(d) memory for d distinct lines, which the constraints explicitly allow. The pitfalls are small but real. Don't sort, because that destroys first-appearance order. Don't lowercase or trim anything, since "x" and "X" must stay separate. Don't treat the empty string as falsy and skip it, which bites in JavaScript and Python if you write sloppy truthiness checks. Example 2 tests exactly that. For the memory follow-up, mention hashing each line to a fixed-size digest, or an external sort-based approach, but only after the in-memory version passes. If you freeze mid-assessment, StealthCoder is the safety net that hands you the clean version.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Implement uniq: Unique Lines cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Vanta's OA.
Vanta reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Implement uniq: Unique Lines FAQ
How hard is the Vanta Implement uniq question really?+
Easy on the algorithm. It's a single pass with a hash set. The difficulty is in the details: preserving order, treating empty strings as valid lines, and keeping comparison case-sensitive. Get those three right and the base function is done in a few minutes.
What's the trick to getUniqueLines?+
Keep a set of lines you've seen and a result list. For each line, if it's not in the set, add it to both. This preserves first-appearance order automatically, and lookups are O(1) on average, so the whole thing is linear.
Why not just convert the array to a set?+
In some languages a plain set loses insertion order, so you can't trust the output order. Even where order is kept, building the result explicitly is clearer and safer. Use a set for membership checks and a list for output.
How should I answer the too-large-for-memory follow-up?+
Say the in-memory version needs space proportional to distinct lines. For huge files, store a fixed-size hash of each line instead of the full text, or use external sorting while tracking original line numbers to restore order. Mention the collision tradeoff for hashing.
How do I prepare for this in 48 hours?+
Write the set-plus-list solution from memory in your language. Then test it on empty strings, case differences, all-duplicate input, and an empty array. Rehearse a two-sentence answer for the memory follow-up. That covers essentially everything this question can throw at you.