PracHub
QuestionsPremiumLearningGuidesInterview PrepCoaches
|Home/Coding & Algorithms/Bloomberg

Implement a simplified grep with extensible flags

Last updated: Mar 29, 2026

Quick Overview

This question evaluates competency in designing maintainable, extensible text-processing code, covering flag parsing, separation of concerns, and correct substring matching behavior.

  • medium
  • Bloomberg
  • Coding & Algorithms
  • Software Engineer

Implement a simplified grep with extensible flags

Company: Bloomberg

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem Implement a simplified version of `grep` that searches a text file and returns the lines that match a given query string. You should focus on **clean, readable, extensible design** (e.g., parsing flags/options in a way that makes it easy to add new flags later), not on advanced algorithms. ## Requirements - Input: - `pattern`: a non-empty string to search for. - `lines`: an array/list of strings representing the file content, one element per line. - `flags/options`: a set of optional flags (you may choose the interface, e.g., CLI args, a struct/object, or a map). - Output: - The matching lines, in original order. ## Supported flags (minimum) Define at least a few flags and implement them, such as: - Case-insensitive match (e.g., `-i`) - Print line numbers along with matched lines (e.g., `-n`) - Invert match (return non-matching lines) (e.g., `-v`) ## Notes - Assume a simple **substring match** (not full regex). - Be explicit about edge cases (empty file, empty lines, pattern casing, etc.). - The interviewer will evaluate: - Code organization (separation of concerns: parsing, matching, formatting) - Extensibility (how easy it is to add a new flag) - Correctness and testability ## Example Given: - `pattern = "error"` - `lines = ["ok", "Error: disk full", "no issue", "error again"]` - flags: case-insensitive Output: - `"Error: disk full"` - `"error again"`

Quick Answer: This question evaluates competency in designing maintainable, extensible text-processing code, covering flag parsing, separation of concerns, and correct substring matching behavior.

Related Interview Questions

  • Solve meeting and tree problems - Bloomberg (easy)
  • Check connectivity between two subway stations - Bloomberg (easy)
  • Minimize travel cost with two cities - Bloomberg (easy)
  • Find tree root and bucket numbers - Bloomberg (hard)
  • Design a data structure for dynamic top‑K frequency - Bloomberg (hard)
Bloomberg logo
Bloomberg
Dec 15, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
4
0

Problem

Implement a simplified version of grep that searches a text file and returns the lines that match a given query string.

You should focus on clean, readable, extensible design (e.g., parsing flags/options in a way that makes it easy to add new flags later), not on advanced algorithms.

Requirements

  • Input:
    • pattern : a non-empty string to search for.
    • lines : an array/list of strings representing the file content, one element per line.
    • flags/options : a set of optional flags (you may choose the interface, e.g., CLI args, a struct/object, or a map).
  • Output:
    • The matching lines, in original order.

Supported flags (minimum)

Define at least a few flags and implement them, such as:

  • Case-insensitive match (e.g., -i )
  • Print line numbers along with matched lines (e.g., -n )
  • Invert match (return non-matching lines) (e.g., -v )

Notes

  • Assume a simple substring match (not full regex).
  • Be explicit about edge cases (empty file, empty lines, pattern casing, etc.).
  • The interviewer will evaluate:
    • Code organization (separation of concerns: parsing, matching, formatting)
    • Extensibility (how easy it is to add a new flag)
    • Correctness and testability

Example

Given:

  • pattern = "error"
  • lines = ["ok", "Error: disk full", "no issue", "error again"]
  • flags: case-insensitive

Output:

  • "Error: disk full"
  • "error again"

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Bloomberg•More Software Engineer•Bloomberg Software Engineer•Bloomberg Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.