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.