Unit 2 Session 1 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
Q: What is the problem asking for?
Q: What are the inputs?
vip_passes
and guests
, where vip_passes
represents the types of guests with VIP passes and guests
represents the types of guests at the festival.Q: What are the outputs?
Q: Are the characters case-sensitive?
Plan the solution with appropriate visualizations and pseudocode.
For this problem, the Plan step was provided to you.
1. Create an empty set called vip_set.
2. For each character in vip_passes, add it to vip_set.
3. Initialize a counter variable to 0.
4. For each character in guests:
- If the character is in vip_set, increment the count by 1.
5. Return the count.
def num_VIP_guests(vip_passes, guests):
# Step 1: Create an empty set called vip_set
vip_set = set()
# Step 2: For each character in vip_passes, add it to vip_set
for vip in vip_passes:
vip_set.add(vip)
# Step 3: Initialize a counter variable to 0
count = 0
# Step 4: For each character in guests, if it is in vip_set, increment the count
for guest in guests:
if guest in vip_set:
count += 1
# Step 5: Return the count
return count