Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Detect Repeated Patterns in Logs
00:00
5 left

Detect Repeated Patterns in Logs

HardPython

Problem

Trend Micro Vision One can inspect network log strings for recurring signatures. Given a log string, detect every distinct pattern of a specified length that appears at least twice within one contiguous sliding window.

Return patterns in the order they are first confirmed as repeated. A pattern should appear only once in the result, even if it repeats in multiple windows. Occurrences may overlap.

Formal Specification

Implement detect_repeated_patterns(logs, pattern_length, window_length).

  • logs is a string of lowercase English letters representing a normalized log stream.
  • pattern_length is the length of each pattern to inspect.
  • window_length is the length of each sliding window.
  • Return a list of distinct strings, each of length pattern_length.

Two occurrences qualify if both complete substrings fit inside some window of length window_length. Equivalently, their starting indices differ by at most window_length - pattern_length.

Constraints

  • 1 <= len(logs) <= 10^5
  • 1 <= pattern_length <= window_length <= len(logs)
  • logs contains only lowercase English letters
  • Overlapping occurrences are valid

Function Signature

def detect_repeated_patterns(logs, pattern_length, window_length):
Interviewer

Your question is Detect Repeated Patterns in Logs. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.