NewProject Coding is here — build features and fix bugs in real codebases with an AI assistantSee what's new

Design an in-memory key-value store that supports efficient value lookup by key prefix.

Implement the KVStore class:

  • KVStore() Initialize an in-memory key-value store.
  • void set(String key, int value) Insert a new key-value pair. Throw an error if the key already exists.
  • int get(String key) Return the current value for key, or -1 if absent.
  • void update(String key, int value) Overwrite the value for an existing key. Throw an error if the key is missing.
  • void deleteKey(String key) Remove key if it exists.
Test Cases
Input
Output
Expected