Check In

Check In

You're given a list of attendees who have checked in, and a list of names to look up. For each lookup, report whether that name is among the checked-in attendees.

checkIn(attendees, queries)

Return one boolean per query, in order.

Input format: attendees | queries — space-separated names divided by a pipe. Output the booleans as true/false, space-separated.

Examples

checkIn(["ann", "bob"], ["bob", "cat"])  // → [true, false]
checkIn(["x"], ["x", "x"])               // → [true, true]
checkIn([], ["a"])                       // → [false]

Walkthrough

Thinking it through

This problem asks the same question over and over: "is this name among the attendees?" Scanning the whole attendee list for every query works, but it adds up — the total work grows with the number of attendees times the number of queries.

Spotting the repeated-question pattern

The attendee list never changes across queries — only the name you're asking about changes. Whenever you ask the same kind of question against the same fixed collection many times, pay a one-time setup cost so each individual question becomes fast.

Building the approach

  1. Do the setup once: put every attendee into a hash set. This costs time proportional to the number of attendees, done a single time.
  2. For each query, ask the set whether it contains that name — a constant-time check, not a linear search.
  3. Record the true/false result for each query, in the order the queries were given.

Why this beats the naive approach

Without the set, q queries against n attendees cost roughly n times q. With the set, building it costs n once, and each of the q queries costs a small constant amount — roughly n plus q. For small inputs the difference is invisible, but as either number grows, the gap between "n times q" and "n plus q" gets enormous.

Handling the edges

Duplicate queries are handled naturally — each is answered independently by the set, so repeats just produce the same answer twice. An empty attendee list also just works: the set is empty, and every check correctly comes back false.

main.py
Console
Press Run to execute your code, or Submit to test and complete this problem.