← Stripe Interview Insights

Stripe·Software Engineer·Onsite - Coding / Algorithms·Senior

SeniorPrefer not to say
May 2026

Summary

Stripe SWE interview that was basically a single sprawling coding problem about payment card validation, broken into four progressively nastier sub-parts. The last two parts (wildcards and corrupted cards) are where things get genuinely hard and I don't think I fully nailed either.

Questions Asked (4)

Q1

Design and implement a payment card validation system that handles VISA cards (16 digits starting with 4) using the Luhn checksum algorithm.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Warmup part, and I actually fumbled the Luhn implementation on the first try because I mixed up which digits get doubled.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and edge cases, then outline the validation steps: check card type (VISA), length (16 digits), and Luhn checksum. Implement the Luhn algorithm efficiently, and discuss trade-offs like input sanitization, error handling, and potential optimizations.

Pro tip: Mention that while Luhn catches most accidental errors, it's not a security measure; for production, you'd also validate with a payment processor and consider PCI compliance.

1. Clarify Requirements

Ask about input format (string vs. number), expected output (boolean or error details), and whether to handle only VISA or other card types.

2. Outline Validation Steps

Describe the sequence: remove non-digit characters, check length and prefix, then apply Luhn checksum.

3. Explain Luhn Algorithm

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

4. Implement Efficiently

Write clean code, possibly in a single pass from right to left, and discuss time/space complexity (O(n) time, O(1) space).

5. Discuss Edge Cases and Trade-offs

Cover empty input, non-numeric characters, leading zeros, and mention that Luhn is not foolproof; discuss error handling and extensibility.

Key Points to Mention

  • Luhn algorithm steps: doubling alternate digits from the right, summing digits, and modulo 10 check.
  • VISA card specifics: 16 digits, starts with 4.
  • Input sanitization: removing spaces, hyphens, or other non-digit characters.
  • Time and space complexity: O(n) time, O(1) space.
  • Limitations of Luhn: detects single-digit errors and most transpositions, but not all; not a security measure.
  • Production considerations: PCI compliance, tokenization, and integration with payment gateways.

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

Q2

Extend the validator to support multiple card networks: VISA, Mastercard (16 digits, prefixes 51-55), and Amex (15 digits, prefixes 34 or 37). Return appropriate error codes for unknown networks or failed checksums.

Algorithms & Data StructuresAPI & Integrations
Author's notes

Straightforward extension of the first part.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Design a modular validator with a registry of card networks, each defining its own length and prefix rules. Implement a two-phase validation: first identify the network based on prefixes and length, then apply the Luhn checksum. Return specific error codes for unknown networks and checksum failures.

Pro tip: Mention that in production systems like Stripe, card validation is often combined with BIN lookup services for real-time network detection, but for this exercise, a rule-based approach suffices. Also, highlight the importance of not logging full card numbers for security.

1. Define network specifications

Create a data structure (e.g., map or list) that maps each network to its required length(s) and prefix patterns. For example, VISA: length 16, prefix '4'; Mastercard: length 16, prefixes '51'-'55'; Amex: length 15, prefixes '34' or '37'.

2. Implement network detection

Given a card number, iterate through the network specifications to find a match based on length and prefix. If no match, return an 'unknown network' error code.

3. Apply Luhn checksum

Once the network is identified, validate the card number using the Luhn algorithm. If the checksum fails, return a 'checksum failure' error code.

4. Return validation result

If all checks pass, return success (e.g., true or a success code). Otherwise, return the appropriate error code (e.g., 'unknown_network', 'invalid_checksum').

Key Points to Mention

  • Modular design: separate network rules from validation logic for extensibility.
  • Luhn algorithm implementation details (e.g., doubling every second digit from the right).
  • Error handling: distinct error codes for unknown network vs. checksum failure.
  • Edge cases: handling spaces or hyphens in input, non-numeric characters, and empty input.
  • Performance considerations: O(n) time complexity for Luhn, and efficient prefix matching.
  • Security: avoid logging sensitive card data; consider tokenization in real systems.

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

Q3

Handle redacted card numbers containing 1 to 5 wildcard characters ('*'). For each network, count how many valid completions exist and output the counts sorted alphabetically by network name.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where it got rough.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem: each network has a set of valid card number patterns (e.g., prefixes and lengths). For each redacted number, generate all possible completions by replacing '*' with digits, then check each completion against the network rules. Count valid completions per network and sort the results alphabetically by network name.

Pro tip: Precompute the valid card number patterns for each network and use a trie or prefix matching to efficiently validate completions, especially if the number of wildcards is large. Also, consider that the number of completions can be huge (10^5), so avoid brute-force enumeration if possible; instead, use dynamic programming or combinatorics to count valid completions directly.

1. Clarify requirements and constraints

Ask about the exact format of card numbers, the definition of 'valid' for each network (e.g., length, prefix, Luhn check), and the maximum number of wildcards. Confirm that output should be sorted alphabetically by network name.

2. Design a validation function

Implement a function that checks if a fully specified card number is valid for a given network. This may involve checking length, prefix ranges, and possibly the Luhn algorithm.

3. Choose an efficient counting strategy

If wildcards are few (≤5), brute-force enumeration (10^5) is acceptable. For larger wildcards, use dynamic programming over positions, tracking prefix validity and remaining length, or use a trie of valid patterns to prune early.

4. Implement and test

Write code to count valid completions per network, ensuring edge cases like leading zeros, varying lengths, and overlapping network rules are handled. Test with sample inputs and verify counts.

5. Sort and output results

Collect counts in a dictionary keyed by network name, then output them sorted alphabetically by network name, as required.

Key Points to Mention

  • Definition of valid card numbers per network (length, prefix, Luhn check).
  • Handling of wildcards: brute-force vs. dynamic programming vs. trie-based pruning.
  • Time and space complexity analysis, especially with up to 5 wildcards (10^5 possibilities).
  • Edge cases: leading zeros, multiple networks matching the same number, empty results.
  • Sorting output alphabetically by network name.
  • Potential optimizations: precomputing valid patterns, using bitmask or DP state.

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

Q4

Handle corrupted card numbers ending in '?' where exactly one error was introduced: either a single digit was changed, or two adjacent digits were swapped. Enumerate all valid original card numbers with their network names, sorted numerically.

Algorithms & Data StructuresSystem Design
Author's notes

Hardest part by a mile.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the card network validation rules (e.g., Luhn check, prefixes, lengths) and the exact meaning of 'one error'. Then, for each possible original digit at the '?' position, generate candidate numbers by reversing the two error types (digit change and adjacent swap), validate each candidate against all rules, and collect valid ones. Finally, sort the valid numbers numerically and output them with their network names.

Pro tip: Mention that you would precompute network rules and use a trie or prefix table for fast prefix matching, and emphasize that the number of candidates is small (at most 20 per error type), so brute-force reversal is efficient and avoids overcomplicating.

1. Clarify rules and constraints

Ask the interviewer to confirm the card network validation rules (Luhn algorithm, accepted lengths, and prefix ranges) and that exactly one error (digit change or adjacent swap) occurred. Also confirm the output format: list of original numbers with network names, sorted numerically.

2. Generate candidate originals

For the single '?' position, try all 10 digits to form a base number. Then, for each base, generate candidates by reversing a digit change (replace each digit with 0-9) and reversing an adjacent swap (swap each adjacent pair). Deduplicate candidates.

3. Validate candidates

For each candidate, check if it satisfies the Luhn algorithm, has a valid length, and matches a known network prefix. If valid, record the number and its network name.

4. Sort and output

Collect all valid original numbers, sort them numerically, and output each with its network name. Ensure no duplicates and that the sorting is correct (e.g., as integers, not strings).

Key Points to Mention

  • Luhn algorithm implementation and edge cases (e.g., check digit calculation).
  • Card network identification via prefix ranges (e.g., Visa starts with 4, Mastercard 51-55 or 2221-2720, Amex 34/37).
  • Handling both error types: single digit change and adjacent swap, and ensuring no double-counting.
  • Efficiency: the search space is small (at most 10 + 9*2 = 28 candidates per '?' position), so brute-force is acceptable.
  • Sorting numerically and outputting with network names, possibly using a map from number to network.
  • Edge cases: '?' at the beginning or end, leading zeros, and numbers that could belong to multiple networks (though typically prefixes are disjoint).

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