Skip to content
kyra-ptn edited this page Aug 14, 2025 · 2 revisions

Unit 2 Session 1 (Click for link to problem statements)

Problem Highlights

  • 💡 Difficulty: Easy
  • Time to complete: 5-10 mins
  • 🛠️ Topics: Arrays, Membership Checking

1: U-nderstand

Understand what the interviewer is asking for by using test cases and questions about the problem.

  • Established a set (2-3) of test cases to verify their own solution later.
  • Established a set (1-2) of edge cases to verify their solution handles complexities.
  • Have fully understood the problem and have no clarifying questions.
  • Have you verified any Time/Space Constraints for this problem?
  • What should be returned if a is empty?
    • Return True because an empty list is a subset of any list.
  • Can b have duplicates?
    • Yes, duplicates in b do not affect the result.
HAPPY CASE
Input: a = [1, 2], b = [1, 2, 3]  
Output: True  
Explanation: Every element in a exists in b.

Input: a = [3, 3], b = [1, 2, 3]  
Output: True  
Explanation: All instances of 3 in a exist in b.

EDGE CASE
Input: a = [], b = [1, 2, 3]  
Output: True  
Explanation: An empty list is trivially a subset.

Input: a = [4], b = [1, 2, 3]  
Output: False  
Explanation: 4 does not exist in b.

3: P-lan

Plan the solution with appropriate visualizations and pseudocode.

General Idea:
Check if every element in list a is present in list b.

  1. Iterate through each element in list a: a) If the element is not in b, return False
  2. After looping through the full list, return True

⚠️ Common Mistakes

  • Not considering empty lists or duplicates

4: I-mplement

Implement the code to solve the algorithm.

def all_in(a, b):

    for elem in a:
        if elem not in b:
            return False
    return True
Clone this wiki locally