Re:Most candidates cannot solve this interview problem
by Supermancho on Sunday February 07, 2021 @04:41AM
(#26053844)
> the output requested isn't quoted.
Input: "aaaabbbcca"
Output: [("a", 4), ("b", 3), ("c", 2), ("a", 1)]
The input and output is explicit. The interpretation is a talking point.
Serialization into parens is not native for most? scripting languages. Creating a string would probably be most efficient for the output format, for sure. It's important to remember that interview questions are not just about the algorithm (for which this is trivial) but the requirements. Asking if the double quotes are representing strings (and what kind of strings for some languages) is part of the natural back-and-forth of an interview.
The input string is quoted, so the output appears to be an array (not a string type).
My stab at it in Javascript resulted in:
This outputs `[["a",2],["b",2],["c",1],["d",2],["e",1]]`. Without native tuples in Javascript (or JSON), I could construct a string which replaces the inner brackets with parens, but that would be pretty contrived, as the output requested isn't quoted.