FastPrepExtensible Grep Line Filter
Problems/Extensible Grep Line Filter

Extensible Grep Line Filter

Bloomberg LP logoBloomberg LP● EasyNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Bloomberg new grad phone screen. The report asks for a clean, simple grep that returns the lines of a file that contain a target string, and that can be extended with flags. It does not keep the names of the flags or what they do. We chose to pass the file lines as a serialized list and to support the usual -i and -v flags. Our version is about 84% the same as the reported question.

Given the lines of a text file as the array lines, a string pattern, and an array flags, return every line that a simplified grep command selects. Keep the lines in file order, keep duplicate lines, and return each line exactly as written.

A line matches when it contains pattern as a substring (characters next to each other, in order). An empty pattern matches every line. The flags in flags may come in either order:

  • -i makes matching ignore upper and lower case for ASCII letters.
  • -v flips the final result, so the lines that do not match are returned.

Function

grepLines(lines: String[], pattern: String, flags: String[]) → String[]

Examples

Example 1

lines = ["error: disk full","INFO ready","network error"]pattern = "error"flags = []return = ["error: disk full","network error"]

With no flags, matching is case-sensitive. Only the first and third lines contain error.

Example 2

lines = ["Error","all good","ERROR again"]pattern = "error"flags = ["-i"]return = ["Error","ERROR again"]

The -i flag ignores case, so Error and ERROR again match. They are returned with their original case.

Example 3

lines = ["warn","ok","WARN"]pattern = "warn"flags = ["-v","-i"]return = ["ok"]

With -i, both warn and WARN match. Then -v flips the result, so only ok is returned.

Constraints

  • 0 <= lines.length <= 10000.
  • 0 <= lines[i].length <= 500.
  • 0 <= pattern.length <= 100.
  • 0 <= flags.length <= 2.
  • Every line and pattern contains printable ASCII characters.
  • flags contains unique values chosen from -i and -v.

More Bloomberg LP Phone Screen questions

  • Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
  • Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
  • Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Restricted Decimal Number ValidatorLinkedIn · PHONE SCREEN
  • Validate Timestamped Message RecordsStripe · PHONE SCREEN
  • Format CSV Rows as an ASCII TableAmazon · PHONE SCREEN
  • Compare Calendar DatesWells Fargo · PHONE SCREEN
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEW
  • CSV Row SerializerMercor · PHONE SCREEN
  • Host Log ParserVerkada · PHONE SCREEN
  • Length-Prefixed String CodecSnowflake · PHONE SCREEN
  • Machine Message RouterOpenAI · PHONE SCREEN
  • Parse and Query Server LogsKikoff · PHONE SCREEN
See Bloomberg LP hiring insights
Saved
class Solution {
    public String[] grepLines(String[] lines, String pattern, String[] flags) {
        // Write your code here.
    }

}
Checking account…