← Stripe Interview Insights

Stripe·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026Remote

Summary

Stripe coding interview focused entirely on a multi-part credit card validation problem. Four progressively harder tasks built on each other, starting from basic Luhn checks and ending with error-correction enumeration. The last two parts were rough.

Questions Asked (4)

Q1

Given a digit-only card number string, implement a function that checks whether it passes the Luhn checksum and, if valid, returns which brand it belongs to (VISA, MASTERCARD, or AMEX), or INVALID_CHECKSUM otherwise.

Algorithms & Data Structures
Author's notes

This part was fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements and edge cases, then outline the Luhn algorithm step-by-step. After validating the checksum, determine the card brand based on known prefix and length patterns, and return the appropriate result. Write clean, modular code with tests for edge cases.

Pro tip: Mention that you would strip non-digit characters and handle empty strings gracefully, and discuss how to extend the solution for new card brands without modifying core logic.

1. Clarify requirements and edge cases

Ask about input format (spaces, hyphens), expected return values, and whether to handle unknown brands. Confirm that only digit-only strings are considered.

2. Implement Luhn checksum validation

Describe the algorithm: starting from the rightmost digit, double every second digit, sum digits of products, and check if total modulo 10 is zero.

3. Identify card brand using patterns

Use known prefixes and lengths: VISA starts with 4 (length 13/16/19), MASTERCARD starts with 51-55 or 2221-2720 (length 16), AMEX starts with 34 or 37 (length 15).

4. Return appropriate result

If Luhn fails, return INVALID_CHECKSUM. If Luhn passes but brand unknown, decide on a default (e.g., INVALID_BRAND or UNKNOWN). Otherwise return the brand.

5. Test and optimize

Write unit tests for valid and invalid cases, including edge cases like empty string, single digit, and very long numbers. Discuss time/space complexity.

Key Points to Mention

  • Luhn algorithm steps: doubling every second digit from the right, summing digits, modulo 10 check.
  • Card brand identification rules: VISA (prefix 4, lengths 13/16/19), MASTERCARD (prefix 51-55 or 2221-2720, length 16), AMEX (prefix 34/37, length 15).
  • Handling non-digit characters: strip them before processing, but clarify if input is guaranteed digit-only.
  • Edge cases: empty string, single digit, strings with spaces, very long numbers, and unknown brands.
  • Time and space complexity: O(n) time, O(1) space if processing from right to left without extra storage.
  • Code modularity: separate checksum validation from brand detection for maintainability and extensibility.

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

Q2

Extend the previous function so that a number passing the Luhn check but not matching any known brand pattern returns UNKNOWN instead of being lumped in with invalid results.

Algorithms & Data Structures
Author's notes

Basically a one-liner extension of part 1.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the existing function's behavior and the brand detection logic. Then, modify the control flow so that after a successful Luhn check, if no brand pattern matches, return UNKNOWN instead of an invalid result. Ensure that invalid Luhn checks still return the appropriate invalid status.

Pro tip: Mention that UNKNOWN should be a distinct return value from invalid, and consider how this change affects downstream consumers and tests. Also, discuss the importance of maintaining backward compatibility if the function is part of a public API.

1. Understand the current implementation

Review the existing function to see how it currently handles Luhn validation and brand detection. Identify where the invalid result is returned.

2. Separate Luhn validation from brand detection

Ensure that the Luhn check is performed first. If it fails, return the invalid result immediately.

3. Introduce UNKNOWN for unmatched brands

After a successful Luhn check, attempt to match brand patterns. If no pattern matches, return UNKNOWN instead of invalid.

4. Update tests and documentation

Add test cases for numbers that pass Luhn but match no brand, and update any documentation to reflect the new UNKNOWN return value.

5. Consider edge cases and integration

Think about how this change impacts other parts of the system, such as API responses or error handling, and ensure consistency.

Key Points to Mention

  • Luhn algorithm validates the number's checksum, not the brand.
  • Brand detection relies on pattern matching (e.g., regex for prefixes).
  • UNKNOWN is a distinct state from invalid, indicating a valid number with unrecognized brand.
  • Return early on Luhn failure to avoid unnecessary brand checks.
  • Update unit tests to cover the new UNKNOWN case.
  • Consider backward compatibility if the function is used elsewhere.

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

Q3

Allow the card number input to contain wildcard characters where each wildcard represents any single digit. Return the count of valid card numbers per brand that the pattern could represent, formatted as brand-count pairs.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where things got interesting.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem: define the card brands and their valid number patterns (e.g., length, prefixes). Then, for each brand, count how many numbers matching the brand's pattern also match the wildcard pattern, using combinatorics or digit DP. Finally, return the counts as brand-count pairs.

Pro tip: Mention that wildcard matching can be done efficiently with digit DP, but for fixed-length patterns, a simple per-position check suffices. Also, discuss how to handle overlapping brand patterns and ensure counts are exact.

1. Clarify requirements and constraints

Ask about the set of card brands, their validation rules (length, prefixes, Luhn check), and whether the wildcard pattern is fixed-length. Confirm the output format.

2. Define brand patterns

Represent each brand's valid numbers as a set of constraints (e.g., length, prefix ranges). This may involve pre-processing brand rules into a structured format.

3. Count matches per brand

For each brand, count the number of digit strings that satisfy both the brand's constraints and the wildcard pattern. Use combinatorics if constraints are simple, or digit DP for complex constraints.

4. Handle overlaps and edge cases

Consider if a number can belong to multiple brands (e.g., due to overlapping prefixes). Decide whether to count it for each brand or resolve conflicts. Also handle patterns with no wildcards or all wildcards.

5. Format and return results

Output the counts as brand-count pairs, ensuring the order matches the expected format (e.g., sorted by brand name or as given).

Key Points to Mention

  • Card brand validation rules (length, prefix ranges, Luhn algorithm if applicable)
  • Wildcard pattern matching techniques (digit DP, combinatorics, regex)
  • Time and space complexity analysis, especially for large patterns or many brands
  • Handling overlapping brand patterns and potential double-counting
  • Edge cases: empty pattern, no wildcards, all wildcards, invalid brands
  • Trade-offs between pre-computing brand patterns vs. on-the-fly matching

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

Q4

Given a card number string where a trailing '?' indicates exactly one error occurred to the preceding digits (the error being one of: a changed digit, a removed digit, an added digit, or a transposition of two adjacent digits), enumerate all originally valid card numbers and their brands that could have produced the observed string.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I basically ran out of time here.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem: the observed string has a trailing '?' indicating exactly one error (change, removal, addition, or transposition) occurred to the preceding digits. Then, systematically generate all possible original valid card numbers by reversing each error type, validate them using Luhn's algorithm and brand-specific patterns (e.g., Visa, Mastercard), and return the unique set with their brands.

Pro tip: Emphasize that the solution must be efficient and scalable, as card numbers can be long and multiple errors could be considered in production; also mention the importance of using Luhn's checksum and brand regexes to prune invalid candidates early.

1. Clarify requirements and constraints

Confirm the definition of 'valid' (Luhn checksum and brand-specific patterns) and the exact meaning of the trailing '?' (exactly one error of the specified types). Ask about input size and performance expectations.

2. Enumerate possible original numbers

For each error type, generate all possible original strings by reversing the error: for changed digit, try all 10 digits at each position; for removed digit, insert a digit at each position; for added digit, remove each digit; for transposition, swap each adjacent pair.

3. Validate candidates

For each candidate, check if it passes Luhn's algorithm and matches a known card brand pattern (e.g., Visa starts with 4, Mastercard 51-55 or 2221-2720, etc.). Collect valid ones with their brands.

4. Deduplicate and return results

Remove duplicates (since different error reversals might yield the same original number) and return the list of unique valid card numbers with their brands.

5. Analyze complexity and trade-offs

Discuss time and space complexity: O(n * 10) for changes, O(n) for insertions/removals, O(n) for transpositions, where n is the length of the observed string. Mention potential optimizations like early pruning using brand prefixes.

Key Points to Mention

  • Luhn's algorithm for checksum validation
  • Card brand identification patterns (Visa, Mastercard, Amex, Discover, etc.)
  • Error types: digit change, removal, addition, adjacent transposition
  • Systematic enumeration by reversing each error type
  • Deduplication of results
  • Time and space complexity analysis and potential optimizations

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