Reported July 2026
Appledesign

Phone Directory

Reported by candidates from Apple's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Apple OA. Under 2s to a working solution.
Founder's read

Apple reported this one in July 2026, and the detail that matters is the ADD rule: a name has one phone, a phone has one name, and a conflicting ADD wipes the old pair. It's a Phone Directory, two hash maps kept in sync, five operations, one output list. The code looks trivial until an overwrite leaves a stale reverse entry. If you're taking this OA in the next couple of days, the work is getting ADD right, not the lookups. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but this is a pattern you can own tonight.

The problem

Implement a bidirectional phone directory that supports name-to-phone and phone-to-name lookups.
The directory supports adding an entry, looking up by phone, looking up by name, removing by name, and removing by phone.
Each operation is a string array:
["ADD", name, phone]: add or update the directory entry. A name can have at most one phone number, and a phone number can belong to at most one name. If the new name or phone already exists, remove the old conflicting mapping before storing the new pair. This operation produces no output.
["GET_NAME", phone]: append the associated name, or "" if the phone number is absent.
["GET_PHONE", name]: append the associated phone number, or "" if the name is absent.
["REMOVE_NAME", name]: remove the entry for that name and append "true" if an entry was removed, otherwise append "false".
["REMOVE_PHONE", phone]: remove the entry for that phone number and append "true" if an entry was removed, otherwise append "false".
Return all appended outputs in order.
What the interview report shared
The report shared the phone-directory class shape and the five operations above. It also showed that updates should keep the two maps in sync when an existing name or phone number is overwritten.
The shared code appeared to have a small typo in remove_by_phone; the intended behavior is the same as remove_by_name: remove the entry from both directions.

Function
processPhoneDirectory(operations: String[][]) → String[]

Examples
Example 1
operations = [["ADD","Alice","111"],["ADD","Bob","222"],["GET_NAME","111"],["GET_PHONE","Bob"],["REMOVE_PHONE","111"],["GET_PHONE","Alice"]]
return = ["Alice","222","true",""]
111 belongs to Alice and Bob's phone is 222. Removing phone 111 deletes Alice's reverse mapping, so the final lookup by Alice returns an empty string.
Example 2
operations = [["ADD","Alice","111"],["ADD","Alice","333"],["GET_NAME","111"],["GET_PHONE","Alice"],["ADD","Bob","333"],["GET_PHONE","Alice"],["GET_NAME","333"]]
return = ["","333","","Bob"]
Updating Alice from 111 to 333 removes the old phone lookup. Adding Bob with 333 then removes Alice's mapping because a phone number can belong to only one name.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Keep two maps: nameToPhone and phoneToName. The trick is ADD. Before storing (name, phone), check if name already exists and delete its old phone from phoneToName. Then check if phone already exists and delete its old name from nameToPhone. Only then write both directions. Example 2 shows why: Alice moves from 111 to 333, then Bob takes 333 and Alice loses her mapping entirely. The common pitfall is updating only one map, so GET_NAME on an old phone returns a ghost. The other trap is the typo mentioned in the report: REMOVE_PHONE must delete both directions, same as REMOVE_NAME. Return "true" or "false" as strings, and "" for misses. Every operation is O(1), so total time is linear in operations. If you freeze on the ordering of the cleanup steps, StealthCoder is the hedge during the live OA, but the logic fits on a notecard.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Phone Directory cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Apple's OA.

Apple reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Phone Directory FAQ

How hard is the Apple Phone Directory OA question really?+

Easy on algorithm, easy to botch on detail. There's no tricky data structure, just two hash maps. Most failures come from ADD not cleaning up both conflicting mappings, or from returning booleans instead of the strings "true" and "false".

What's the trick to ADD?+

Remove conflicts first, then insert. If the name exists, delete its old phone from the reverse map. If the phone exists, delete its old name from the forward map. After that, write both directions. Skipping either check leaves stale entries that break later lookups.

Do I need a bidirectional map library?+

No. Two plain hash maps are enough and are what the problem expects. Wrap them in a class with add, getName, getPhone, removeByName, and removeByPhone, then loop over operations and append outputs.

What edge cases should I test before submitting?+

Test both examples. Also try re-adding the same exact pair, adding an existing name with a new phone, adding a new name with an existing phone, and removing something absent. Check that ADD adds nothing to the output list and misses return an empty string.

How do I prepare for this in 48 hours?+

Write the class from scratch twice without looking. Focus on the ADD cleanup order and the symmetric remove methods. Then run both examples by hand. That's about an hour of work, and it covers this whole design-style pattern.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Apple.

OA at Apple?
Invisible during screen share
Get it