Config Store with Priority Overrides
Updated
Problem statement
You are building a small configuration store. It has several configs: config i is named configs[i] and has the priority priorities[i]. Each config holds its own key/value pairs, and every config starts empty.
The same key can be in more than one config. When that happens, the value from the config with the higher priority wins. The winning value of a key is its value in the highest-priority config that has the key.
Run the operations in operations in order. Each operation returns one string:
["CREATE", config, key, value]adds the pairkey=valueto that config and returns"true". If the config already haskey, nothing changes and it returns"false".["READ", key]returns the winning value ofkey, or"NOT_FOUND"if no config has it.["UPDATE", config, key, value]sets the value ofkeyin that config tovalueand returns"true". If the config does not havekey, nothing changes and it returns"false".["DELETE", config, key]removeskeyfrom that config only and returns"true". If the config does not havekey, it returns"false". Other configs keep their pairs, so a lower-priority value can become the winning value again.["LIST"]returns every key that is in at least one config, sorted in lexicographic order. Each key is written askey=valuewith its winning value, and the entries are joined by commas with no spaces. If no config has any key, it returns the empty string.
Return the strings returned by all the operations, in order.
Function
runConfigStore(configs: String[], priorities: int[], operations: String[][]) → String[]Examples
Example 1
configs = ["base","user"]priorities = [1,5]operations = [["CREATE","base","theme","light"],["CREATE","base","font","arial"],["CREATE","user","theme","dark"],["LIST"],["READ","theme"],["DELETE","user","theme"],["READ","theme"]]return = ["true","true","true","font=arial,theme=dark","dark","true","light"]- The three
CREATEoperations add new pairs, so each returns"true". - Both configs have
theme."user"has the higher priority (5>1), so its valuedarkwins.LISTreturns"font=arial,theme=dark", andREADreturns"dark". - After
themeis deleted from"user", only"base"has it, soREADreturns"light".
Example 2
configs = ["app"]priorities = [3]operations = [["LIST"],["READ","port"],["UPDATE","app","port","80"],["CREATE","app","port","80"],["CREATE","app","port","90"],["UPDATE","app","port","8080"],["LIST"],["DELETE","app","port"],["DELETE","app","port"]]return = ["","NOT_FOUND","false","true","false","true","port=8080","true","false"]- The store starts empty, so
LISTreturns the empty string andREADreturns"NOT_FOUND". UPDATEfails because"app"has noportyet. The firstCREATEaddsport=80. The secondCREATEfails and does not change the value.UPDATEnow works and sets the value to8080, soLISTreturns"port=8080".- The first
DELETEremoves the pair. The second one fails because the pair is gone.
Example 3
configs = ["env","defaults","team"]priorities = [100,1,50]operations = [["CREATE","defaults","mode","safe"],["CREATE","team","mode","fast"],["UPDATE","defaults","mode","slow"],["READ","mode"],["CREATE","env","mode","debug"],["CREATE","env","level","9"],["LIST"],["DELETE","team","mode"],["READ","mode"],["DELETE","env","mode"],["READ","mode"]]return = ["true","true","true","fast","true","true","level=9,mode=debug","true","debug","true","slow"]- The order of
configsdoes not matter, only the priorities:"env"(100) beats"team"(50), which beats"defaults"(1). - Changing
modein"defaults"toslowdoes not change the winner, so the firstREADreturns"fast"from"team". - Once
"env"hasmode, its valuedebugwins, andLISTreturns"level=9,mode=debug". - Deleting
modefrom"team"changes nothing visible, because"env"still wins. After it is deleted from"env"as well, the valueslowfrom"defaults"is read.
Constraints
1 <= configs.length <= 10priorities.length == configs.lengthconfigs[i]has 1 to 10 lowercase English letters, and all config names are different.1 <= priorities[i] <= 10^9, and all priorities are different.1 <= operations.length <= 1000- Every operation has one of the five forms above, and every config name in an operation is in
configs. - Every key has 1 to 10 lowercase English letters. Every value has 1 to 10 characters, each a lowercase English letter or a digit.
More Microsoft Phone Screen questions
- Corporation Reporting LinesPHONE SCREEN · Seen Oct 2026
- Random Forest Classifier from ScratchPHONE SCREEN · Seen Oct 2026
- Least Recently Used CacheOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Greedy and Beam Sentence DecodingPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Top K Frequent ElementsPHONE SCREEN · Seen Sep 2026
- 3SumPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Arithmetic Expression EvaluatorPHONE SCREEN · Seen Sep 2026
- Employee Hierarchy Cycle and Depth AnalysisPHONE SCREEN · Seen Sep 2026
- Most Visited String SectorsPHONE SCREEN · Seen Sep 2026
- Infer a Lexicographically Smallest Alien AlphabetPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
Similar questions at other companies
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Camel CardsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Banking System with Pending Transfer AcceptanceCircle · PHONE SCREENCircle interview questions
- Streaming Top-K Frequent ElementsNVIDIA · PHONE SCREENNVIDIA interview questions
- Versioned Snapshot SetOpenAI · PHONE SCREENOpenAI interview questions
- Interview Slot BookingTrueFoundry · PHONE SCREEN
- Document Enrichment Stream AggregatorBloomberg LP · PHONE SCREENBloomberg LP interview questions
- In-Memory Database with TTL and Historical QueriesZip · PHONE SCREENZip interview questions
- Task Management SystemAirbnb · OAAirbnb interview questions
- Power Cell BankOptiver · OAOptiver interview questions