FastPrepIP Prefix Store

IP Prefix Store

Bloomberg LP logoBloomberg LP● HardNEW GRADONSITE INTERVIEW
Learn

Problem statement

Addresses are binary strings of exactly width bits. Each string in prefixes covers every address starting with it. Add all prefixes, then for each full-width query return lowercase true or false for whether any stored prefix covers it.

Append one final decimal string equal to the number of distinct full-width addresses covered by the union of all prefixes.

Function

runIpPrefixStore(prefixes: String[], queries: String[], width: int) → String[]

Examples

Example 1

prefixes = ["1111","11"]queries = ["1100","1010","1111"]width = 4return = ["true","false","true","4"]

Prefix 11 covers 1100,1101,1110,1111; adding 1111 does not double count.

Constraints

  • 1 <= width <= 60.
  • Prefixes contain only 0/1 and have length at most width.
  • Queries have length exactly width.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String[] runIpPrefixStore(String[] prefixes, String[] queries, int width) {
  // Write your code here.
}
prefixes["1111","11"]
queries["1100","1010","1111"]
width4
expected["true", "false", "true", "4"]
Checking account…