← Stripe Interview Insights

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

Senior
Apr 2026

Summary

Stripe gave me a pretty intense coding round centered entirely on payment card validation. Four parts, escalating complexity, and they wanted complexity analysis and edge case handling throughout. Not a vibe-check interview at all.

Questions Asked (4)

Q1

Implement the Luhn checksum algorithm and use it to validate a 16-digit VISA card number, returning either 'VISA' or 'INVALID_CHECKSUM'.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The Luhn part itself is fine once you remember the direction matters: start from the rightmost non-check digit and double every second one going left.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements: the input is a 16-digit string, and the output should be 'VISA' if the Luhn checksum is valid, otherwise 'INVALID_CHECKSUM'. Then, explain the Luhn algorithm step-by-step, emphasizing the doubling of every second digit from the right and the handling of digits greater than 9. Finally, walk through a code implementation, discussing edge cases and potential optimizations.

Pro tip: Mention that you would validate the input format (e.g., exactly 16 digits, numeric) before applying the Luhn algorithm, and consider discussing how this could be extended to other card types or integrated into a payment system.

1. Clarify Requirements and Assumptions

Confirm that the input is a 16-digit string representing a VISA card number, and the output should be 'VISA' if the checksum is valid, otherwise 'INVALID_CHECKSUM'. Ask if any other validation (e.g., prefix check) is needed.

2. Explain the Luhn Algorithm

Describe the steps: starting from the rightmost digit (the check digit), double the value of every second digit. If doubling results in a number greater than 9, subtract 9 (or sum the digits). Sum all digits and check if the total modulo 10 is 0.

3. Implement the Algorithm

Write code (in a language of your choice) that iterates over the digits from right to left, applies the doubling rule, accumulates the sum, and returns 'VISA' if sum % 10 == 0, else 'INVALID_CHECKSUM'.

4. Test with Examples

Provide a valid VISA test number (e.g., 4111111111111111) and an invalid one (e.g., 4111111111111112) to demonstrate correctness. Walk through the algorithm manually for at least one example.

5. Discuss Edge Cases and Optimizations

Mention handling non-digit characters, varying lengths (though specified as 16), and potential optimizations like processing digits in a single pass without converting to an array.

Key Points to Mention

  • Luhn algorithm steps: doubling every second digit from the right, subtracting 9 if >9, summing all digits, and checking modulo 10.
  • Input validation: ensure the string is exactly 16 digits and contains only numeric characters.
  • Time and space complexity: O(n) time and O(1) space if processed in a single pass.
  • Handling the check digit: the rightmost digit is not doubled; doubling starts from the second digit from the right.
  • Potential integration: how this function could be part of a larger payment validation system.
  • Testing: use known valid and invalid card numbers to verify the implementation.

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, AMEX) with different prefix ranges and lengths, returning the network name, 'INVALID_CHECKSUM', or 'UNKNOWN_NETWORK'.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The Mastercard prefix range (51-55) is where people slip up.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements and edge cases, then design a data-driven solution using a table of network rules (prefixes and lengths). Implement the validation in clear stages: first check the network, then validate the checksum, and finally return the appropriate result.

Pro tip: Mention that you would make the network rules configurable (e.g., via a data structure or external config) to easily add new networks without changing the core logic. Also, discuss the trade-off between hardcoding rules for performance vs. configurability for maintainability.

1. Clarify requirements and edge cases

Ask about the expected input format (string with or without spaces), whether the network detection should be based on prefix only or also length, and how to handle ambiguous cases (e.g., a number that matches multiple networks).

2. Design the data structure for network rules

Propose a table (e.g., array of objects or map) where each entry contains the network name, a list of valid prefixes (or prefix ranges), and valid lengths. This makes the solution extensible and easy to read.

3. Implement network detection

Iterate through the rules to find a matching network based on the card number's prefix and length. If no match, return 'UNKNOWN_NETWORK'.

4. Validate checksum using Luhn algorithm

If a network is matched, apply the Luhn algorithm to verify the checksum. If it fails, return 'INVALID_CHECKSUM'.

5. Return the network name and discuss extensibility

If both checks pass, return the network name. Also mention how the design allows adding new networks by simply updating the rules table.

Key Points to Mention

  • Use of Luhn algorithm for checksum validation
  • Data-driven approach with a rules table for prefixes and lengths
  • Handling of edge cases: empty input, non-numeric characters, ambiguous prefixes
  • Return values: network name, 'INVALID_CHECKSUM', or 'UNKNOWN_NETWORK'
  • Trade-offs: hardcoded vs. configurable rules, performance vs. maintainability
  • Extensibility: how to add new networks without modifying core logic

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

Q3

Given a card number string with 1 to 5 asterisks replacing digits, count how many valid completions exist per network and output them sorted alphabetically.

Algorithms & Data StructuresSystem Design
Author's notes

This is where it got genuinely hard.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the card network rules (prefix ranges and lengths) and the wildcard positions, then for each network count valid completions by checking if the fixed digits match the network's prefix and length constraints, and if so, compute 10^(number of asterisks) as the count. Finally, sort the networks alphabetically and output the counts.

Pro tip: Mention that you would precompute the network rules as a list of (name, length, prefix ranges) and use a trie or simple iteration for efficiency, and note that the count can be huge so you might need to handle big integers or modulo if required.

1. Clarify requirements and constraints

Ask about the exact card network rules (e.g., Visa, Mastercard, Amex) including prefix ranges and valid lengths, and confirm the input format (e.g., asterisks only replace digits, no other characters).

2. Model the problem

Represent each network as a set of rules: a list of valid lengths and a list of prefix ranges (e.g., Visa: length 16, prefix 4; Mastercard: length 16, prefix 51-55 or 2221-2720).

3. Count valid completions per network

For each network, check if the card number's length matches any valid length and if the fixed digits (non-asterisk) are compatible with the network's prefix ranges. If compatible, the number of completions is 10^(number of asterisks).

4. Sort and output

Collect the counts for each network that has at least one valid completion, sort the network names alphabetically, and output the results in the required format.

Key Points to Mention

  • Card network identification rules (prefix ranges and lengths) for major networks like Visa, Mastercard, Amex, Discover.
  • Handling wildcards: each asterisk independently can be any digit 0-9, so the count is 10^k where k is the number of asterisks.
  • Edge cases: no valid completions for a network, multiple networks matching, and very large counts (potential need for big integers).
  • Efficiency: preprocess network rules and avoid unnecessary checks; time complexity O(N * M) where N is number of networks and M is number of prefix ranges.
  • Input validation: ensure the string contains only digits and asterisks, and length is within 1-5 asterisks as given.
  • Output format: sorted alphabetically by network name, and only include networks with count > 0.

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

Q4

Given a card number ending in '?' that indicates exactly one error was introduced (either a single digit change or a swap of two adjacent digits), enumerate all original valid cards consistent with that model, output as '<number>,<NETWORK>' sorted numerically.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Hardest part by far.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: the input is a card number string with exactly one '?' representing a single digit, and exactly one error (either a digit change or adjacent swap) was introduced. Then, systematically generate all possible original numbers by reversing the error model: for each position, try all 10 digits (if it's a digit change) and try swapping adjacent digits (if it's a swap), validate each candidate using Luhn's algorithm and network detection, and collect unique valid cards. Finally, sort the results numerically and output in the required format.

Pro tip: Mention that you would use Luhn's algorithm for validation and a prefix-based network detection (e.g., Visa starts with 4, Mastercard 51-55 or 2221-2720, Amex 34/37, Discover 6011/65). Also, emphasize the importance of deduplication and sorting to handle cases where multiple error models produce the same valid card.

1. Clarify the problem and constraints

Confirm that the input is a string with exactly one '?' and that exactly one error (digit change or adjacent swap) was introduced. Ask about the expected output format, network detection rules, and whether the original card must pass Luhn validation.

2. Enumerate possible original numbers

For each position, consider two error types: (1) if the character is a digit, try changing it to each of the other 9 digits; if it's '?', try all 10 digits. (2) For each adjacent pair, try swapping them. This generates a set of candidate numbers.

3. Validate candidates

For each candidate, check if it passes Luhn's algorithm and matches a known card network prefix. If valid, record it along with its network.

4. Deduplicate and sort

Remove duplicates (since different error models might yield the same valid card) and sort the results numerically by the card number.

5. Format and output

Output each valid card as '<number>,<NETWORK>' in sorted order. Ensure the network name is in the expected format (e.g., 'VISA', 'MASTERCARD').

Key Points to Mention

  • Luhn's algorithm for checksum validation
  • Card network detection based on IIN/BIN prefixes
  • Handling of the '?' placeholder: it represents a single digit, so try all 10 possibilities
  • Two error models: single digit change (including changing the '?' digit) and adjacent swap
  • Deduplication of results because multiple error models can produce the same valid card
  • Sorting numerically (not lexicographically) and output format

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