Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Training Patterns from Inputs

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

Your question is Top Training Patterns from Inputs. 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

Given an array of strings inputs, where each string represents one user input, and an integer k, return the k most frequently occurring training patterns. A pattern is the normalized form of each input after trimming leading/trailing spaces and converting to lowercase. If two patterns have the same frequency, return them in lexicographical order.

Constraints

  • 1 <= len(inputs) <= 10^5
  • 1 <= len(inputs[i]) <= 10^3
  • 1 <= k <= number of distinct normalized patterns
  • Each input string may contain letters, digits, spaces, and punctuation

Function Signature

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