Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Method Name Similarity to Class Name

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

Your question is Method Name Similarity to Class Name. 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

Liftoff code analysis tools need to identify methods whose names are sufficiently similar to their containing classes. Implement a function that determines whether a methodName is close to a className according to the following definition.

Normalize both names by removing every non-alphanumeric character and converting all letters to lowercase. The method is considered close when the Levenshtein edit distance between the normalized names is at most 2. One edit is one insertion, deletion, or substitution of a single character. Transpositions count as two edits.

Formal Specification

  • Input: Two non-empty strings, methodName and className.
  • Output: Return True if their normalized Levenshtein distance is at most 2; otherwise return False.
  • The function must not modify either input string.

Constraints

  • 1 <= len(methodName), len(className) <= 1000
  • Names may contain letters, digits, and separators
  • The edit-distance threshold is fixed at 2
  • Matching is case-insensitive after normalization

Function Signature

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