FastPrepInverted Index Search
Problems/Inverted Index Search

Inverted Index Search

Bloomberg LP logoBloomberg LP● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A senior-level report from a Bloomberg interview loop describes a two-hour onsite coding round. The task was to build a search system that keeps an inverted index in memory, using a data set the interviewers supplied. It does not say what the data looked like, what a query was, or how matches were ordered or checked.

Everything else here is our choice. The data set is a list of documents. Each document is a short line of lowercase words, and its id is its position in the list, starting at 0. A query is one to three words. A document matches when every query word is a whole word of the document, in any order. Each answer lists the matching ids from small to large, and the queries come as a second list. A call has 1 to 500 documents of 1 to 20 words, and 1 to 500 queries, with words of 1 to 10 letters.

Our version is about 65% the same as the reported question.

You are given a list of documents. Each document is a line of words separated by single spaces. The id of a document is its position in the list, starting at 0.

You are also given a list of queries. Each query is one to three words. A document matches a query when every word of the query is a whole word of the document. The order of the words does not matter, and a word that appears more than once still counts once.

For each query, in order, find the ids of all matching documents. Return one list of ids per query, with the ids in increasing order. If no document matches, that list is empty.

A part of a word is not a match: the query app does not match a document that has only the word apple. Think about how to build a lookup once, so that each query does not have to read every document again.

Function

searchIndex(documents: String[], queries: String[]) → int[][]

Examples

Example 1

documents = ["red apple pie","green apple","red pie","apple"]queries = ["apple","red apple","pie red","plum"]return = [[0,1,3],[0],[0,2],[]]

The documents have ids 0, 1, 2 and 3.

  • apple is a word of documents 0, 1 and 3.
  • red apple needs both words: only document 0 has them.
  • pie red needs both words, in any order: documents 0 and 2.
  • plum is in no document, so the answer is an empty list.

Example 2

documents = ["go go go","go stop","stop"]queries = ["go","stop go","go stop stop"]return = [[0,1],[1],[1]]

A word that appears three times in document 0 still counts once, so document 0 shows up once in the answer for go.

stop go needs both words: only document 1 has them. A query word may repeat, and go stop stop means the same as go stop: document 1.

Example 3

documents = ["apple tree","app store","pineapple"]queries = ["app","apple","pine"]return = [[1],[0],[]]

A query word must be a whole word of the document. app is a whole word only in document 1. It is just a part of apple and pineapple, so those do not match.

apple matches document 0 only, and pine matches nothing.

Example 4

documents = ["b a","a","c a b"]queries = ["a","a b","c","b c a"]return = [[0,1,2],[0,2],[2],[2]]

The word a is in all three documents, so the answer is 0, 1, 2 in increasing order.

a b needs both: documents 0 and 2. c is only in document 2. b c a needs all three words, and only document 2 has them.

Constraints

  • 1 <= documents.length <= 500
  • 1 <= queries.length <= 500
  • Each document is 1 to 20 words, and each query is 1 to 3 words. Words are separated by single spaces, with no space at the start or the end.
  • Each word is 1 to 10 lowercase English letters.

More Bloomberg LP Onsite Interview questions

  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • In-Memory Vault File SystemHarvey · ONSITE INTERVIEWHarvey interview questions
  • Implement uniq: Unique LinesVanta · ONSITE INTERVIEW
  • Most-Frequent Next-Word PredictorGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Text Embedding and Vector SearchNike, Inc. · PHONE SCREEN · ONSITE INTERVIEWNike, Inc. interview questions
  • Substitution Cipher Dictionary MatcherRemitly · ONSITE INTERVIEWRemitly interview questions
  • Account Scheduler - Availability and AcquireStripe · ONSITE INTERVIEWStripe interview questions
  • In-Memory Directory and File OperationsSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
  • In-Memory Spreadsheet ValuesRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • File System PathsCapital One · ONSITE INTERVIEWCapital One interview questions

Interview reports that mention this question

  • Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int[][] searchIndex(String[] documents, String[] queries) {
        // Write your code here.
    }
}
Checking account…