๐Ÿ“‡

Contact Book

A contact book you can add to, search, update, delete and list in sorted order.

Project 6Intermediate

๐Ÿงฉ Problem statement

Process commands: “add:NAME:PHONE”, “update:NAME:PHONE”, “delete:NAME”, “search:TEXT” (show “NAME PHONE” for names starting with TEXT, any case), “list” (all contacts in alphabetical order as “NAME PHONE”). Updating or deleting a missing name shows “NAME not found”.

๐Ÿ“‹ Requirements

  • Add
  • Search
  • Update
  • Delete
  • Sort

๐Ÿ“ฅ Inputs

  • COMMANDS: list of text commands

๐Ÿ“ค Outputs

  • Results of search/list and error messages

๐Ÿ“ Rules

  • Names are unique
  • Search matches the start of the name, ignoring case

๐Ÿšง Constraints

  • Up to a few hundred contacts

๐Ÿงญ Suggested approach

  • Store contacts in a map: name โ†’ phone
  • Split commands on ":"
  • For list, SORT(KEYS(BOOK))

๐Ÿง  Required concepts

  • Maps
  • Strings
  • Sorting
โœ๏ธ Pseudocode editor ยท dry-run tool ยท test cases

Design your solution here. Use Run to dry-run it step by step and Run tests to check it. Hints unlock one at a time โ€” try on your own first!

๐Ÿงช Edge cases to test

  • Update or delete a missing contact
  • Search that matches nothing
  • Names with different capitals

๐Ÿ“ˆ Complexity analysis

Add/update/delete: O(1). List and search: O(n log n) because of sorting.

๐Ÿ“– Solution walkthrough (open after youโ€™ve tried!)

A map gives instant lookup by name. Update and delete share one validation check. Search uses SUBSTRING to compare the first letters in lower case. Listing sorts the keys so the output is alphabetical.

๐Ÿš€ Challenge extensions

  • Store several numbers per contact (a list)
  • Search by phone number too
  • Import contacts from a single text line

โ† All projects