Print the K-th non-empty line

Quick Overview

This question evaluates streaming file I/O, memory-efficient data processing, UTF-8 handling, and robustness with edge cases such as blank lines, trailing newlines, and files containing fewer than K non-empty lines, while also requiring reasoning about time and space complexity.

Print the K-th non-empty line

Company: Lyft

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Onsite

Given a large UTF-8 text file, write a program that prints the K-th non-empty line. Do not load the whole file into memory. Specify how you handle files with fewer than K non-empty lines, blank lines, and trailing newline behavior. Provide code in a language of your choice and discuss time and space complexity.

Quick Answer: This question evaluates streaming file I/O, memory-efficient data processing, UTF-8 handling, and robustness with edge cases such as blank lines, trailing newlines, and files containing fewer than K non-empty lines, while also requiring reasoning about time and space complexity.

|Home/Data Manipulation (SQL/Python)/Lyft
Lyft logo
Lyft
Sep 6, 2025, 12:00 AM
mediumSoftware EngineerOnsiteData Manipulation (SQL/Python)
14
0

Given a large UTF-8 text file, write a program that prints the K-th non-empty line. Do not load the whole file into memory. Specify how you handle files with fewer than K non-empty lines, blank lines, and trailing newline behavior. Provide code in a language of your choice and discuss time and space complexity.

Loading comments...