Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Python Text Line Counter

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

Your question is Python Text Line Counter. 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

An Okta System Log export is represented as a list of text lines. Given the lines and a target word, return how many lines contain that word as a contiguous substring, ignoring letter case.

A line is counted at most once, even if the target appears multiple times. Punctuation does not prevent a match, so "MFA denied." contains "mfa".

Formal Specification

Implement count_matching_lines(lines, word):

  • Input: lines, a list of strings, and word, a non-empty string.
  • Output: An integer equal to the number of lines where word occurs as a case-insensitive substring.
  • Do not modify the input list.

Constraints

  • 0 <= len(lines) <= 10^5
  • 0 <= len(line) <= 10^4
  • 1 <= len(word) <= 10^3
  • Lines and the target contain standard Unicode text
  • Matching is case-insensitive substring matching, not whole-word matching

Function Signature

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