Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
QA interview question
ProgrammingJuniorOccasionalPractical

How would you find duplicates or compare character frequencies efficiently?

Answer

Walk the input once and store each value or normalized character in a set or frequency map. A set is enough to detect whether a duplicate exists; counts are needed to report duplicates or compare multisets such as anagrams. Clarify case, whitespace and Unicode rules, then test empty input, repeated values, equivalent normalized text and inputs with no duplicates.

Strong answer includes

  • selects a set or frequency map for the required output
  • states normalization assumptions
  • covers empty, unique and repeated inputs

Practical example

Given the strings 'listen' and 'silent' for an anagram check, a candidate who only compares lowercase letters misses that 'Silent ' with a trailing space and different casing should still count as equivalent once the interviewer clarifies that whitespace and case should be normalized before comparison.

#hash-map#strings#sdet#coding-interview

Sources

MIT OpenCourseWare — Introduction to AlgorithmsMIT OpenCourseWare · Data structures, algorithmic reasoning and time and space complexityUnicode Standard Annex #29 — Text SegmentationUnicode Consortium · Grapheme clusters, text boundaries and user-perceived charactersSoftware Testing Interview Questions and AnswersGeeksforGeeks · Prevalence signal across manual, automation and technical testing topics