Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Normalize Mobile Error Messages

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Normalize Mobile Error Messages. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

At Acme Mobile, different app layers emit inconsistent error strings for the same failure. Implement a reusable error normalization function that groups similar raw error messages under a canonical error key.

Task

Write a function group_errors(errors, rules) that takes a list of raw error strings and a list of normalization rules. Each rule is a pair [pattern, canonical]. For every error string, first normalize it by converting to lowercase and replacing every maximal sequence of digits with #. Then, if the normalized string contains one or more rule patterns, assign the error to the canonical value of the longest matching pattern. If no pattern matches, use the normalized string itself as the key. Return a dictionary mapping each final key to its frequency.

Constraints

  • 1 <= len(errors) <= 10^4
  • 0 <= len(rules) <= 10^3
  • 1 <= len(error) <= 200
  • 1 <= len(pattern), len(canonical) <= 200
  • If multiple rules match, choose the canonical value from the longest matching pattern

Function Signature

def group_errors(errors, rules):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output