FunctionRacerProblemsRace

Consistent Code Book

EasyHash mapsPython, JavaScript, TypeScript, Java, C++

A code book gives every numeric code exactly one name and every name exactly one code. codes and names have the same length: the i-th message used the code codes[i] for the name names[i].

Return True when the messages are consistent with a single code book: every code always came with the same name, and every name always came with the same code. Otherwise return False. Empty lists are consistent.

Example 1

codes [1,2,1]
names ["red","blue","red"]
returns true

Code 1 is always red and code 2 is always blue; each name has one code.

Example 2

codes [1,2,1]
names ["red","blue","green"]
returns false

Code 1 came with red once and green once.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Hash maps problems