← Pinterest Interview InsightsSoftware Engineer

Pinterest·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Pinterest SWE interview with a string problem that looks trivial but has a few gotchas worth thinking through ahead of time.

Questions Asked (1)

Q1

Given two strings, return true if every character in the second string also appears in the first string.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was to sort both strings and do some kind of two-pointer thing, which would've been messier and slower.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: confirm whether the check is case-sensitive, whether duplicate characters in the second string matter, and whether the first string can be preprocessed. Then propose an efficient solution using a hash set or boolean array to store characters from the first string, and iterate through the second string to verify each character's presence. Discuss time and space complexity, and consider edge cases like empty strings or Unicode characters.

Pro tip: Mention that if the character set is small (e.g., ASCII), a boolean array of size 128 or 256 is more memory-efficient and faster than a hash set, but a hash set is more general for Unicode. This shows you consider trade-offs between performance and flexibility.

1. Clarify requirements and constraints

Ask about case sensitivity, character set (ASCII vs Unicode), and whether the second string can have duplicates. This ensures you understand the problem fully before coding.

2. Choose data structure

Decide between a hash set (general, O(1) average lookup) or a boolean array (if character set is known and small). Explain your choice based on constraints.

3. Build set from first string

Iterate through the first string and add each character to the set or mark it in the boolean array. This preprocessing takes O(n) time and O(k) space, where k is the number of unique characters.

4. Check second string

Iterate through the second string and for each character, check if it exists in the set. If any character is missing, return false immediately; otherwise, return true after the loop.

5. Analyze complexity and edge cases

State time complexity O(n+m) and space O(k). Discuss edge cases: empty strings, strings with repeated characters, and Unicode characters if relevant.

Key Points to Mention

  • Time complexity: O(n + m) where n and m are lengths of the first and second strings, respectively.
  • Space complexity: O(k) where k is the number of unique characters in the first string.
  • Choice of data structure: hash set for generality, boolean array for efficiency with small character sets.
  • Early termination: return false as soon as a character in the second string is not found.
  • Edge cases: empty second string returns true, empty first string with non-empty second returns false.
  • Unicode consideration: if strings can contain Unicode, a hash set is safer than a fixed-size array.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.