Pregunta de entrevista de Datadog

Generic pattern matching medium/hard question pasted directly from leetcode.com