FastPrepValidate CSV References and Field Dependencies
Problems/Validate CSV References and Field Dependencies

Validate CSV References and Field Dependencies

Stripe logoStripe● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Stripe new-grad phone screen. The reported exercise includes checking the header and the rows, output of the third column, checking that a value is in another column, and spotting cycles between fields. Our version is about 65% the same as the reported question. We chose plain CSV with no quotes, membership checked against a snapshot, how dependencies are written, the rejection policy, the function signature and the limits. No original examples or full statement were kept.

Check a CSV document using its reference rules and column dependencies. Return the third-column value from each accepted data row, in the original row order.

CSV records

lines[0] is the header. Split each line at every comma, preserving empty cells, then remove surrounding ASCII spaces from every cell. This exercise uses unquoted CSV: commas always separate cells, and quotes have no special meaning.

Return an empty array when the document is empty, the header contains fewer than three cells, a header name is empty after removing surrounding spaces, or two header names are the same after removing those spaces.

A data row is structurally valid when it has exactly as many cells as the header and every trimmed cell is nonempty. Skip other rows, including rows missing the third column.

Cross-column references

Each pair in referenceRules is [sourceColumn, targetColumn], using exact, case-sensitive header names. A structurally valid row passes that rule when its source-column value occurs in the target column of at least one structurally valid row. A row must pass every reference rule.

Build all target-value sets from the same complete set of structurally valid rows. Keep a row’s values in those sets even if that row later fails a reference rule. Do not repeatedly remove rows or rebuild the sets.

Field dependencies

Each pair in dependencies is [field, prerequisite] and represents a directed edge from the first header name to the second. These are dependencies between columns, not between data rows. Return an empty array if the complete field graph has any directed cycle, including a self-loop or a cycle in an otherwise unused component.

Return an empty array if any reference or dependency pair names an unknown header. Repeated pairs are allowed and do not change the answer. When the header, pair names, and dependency graph are valid, return each accepted row's trimmed third cell. Preserve input order and duplicate output values.

Function

validateCsv(lines: String[], referenceRules: String[][], dependencies: String[][]) → String[]

Examples

Example 1

lines = ["id,parent,label","A,A,Alpha","B,A,Beta","C,Z,Gamma","D,,Missing","E,B, Epsilon ","broken,row"]referenceRules = [["parent","id"]]dependencies = [["label","parent"],["parent","id"]]return = ["Alpha","Beta","Epsilon"]

The row for D has an empty parent cell, and the last row has too few cells. Both rows are skipped. The id column of the remaining rows holds A, B, C and E. The row with parent Z fails the reference rule, because Z is not in that set. The other rows pass. The dependencies, label to parent and parent to id, form no cycle. So the answer is the trimmed labels of the passing rows, in order: Alpha, Beta, Epsilon.

Example 2

lines = ["a,b,c","x,y,z"]referenceRules = []dependencies = [["a","b"],["b","a"]]return = []

The field graph contains the cycle a to b to a, so the whole document is rejected.

Example 3

lines = ["left,right,out","a,b,keep","b,z,drop"]referenceRules = [["right","left"]]dependencies = []return = ["keep"]

Both data rows are structurally valid, so the left column gives the set a and b. The first row has right value b, which is in the set, so its value keep is returned. The second row has right value z, which is not in the set, so it fails. The first row may still use b from the second row, even though that row fails its own check. The answer is just keep.

Constraints

  • 0 <= lines.length <= 2001; a header has at most 30 cells.
  • 0 <= referenceRules.length <= 30 and 0 <= dependencies.length <= 900.
  • Every rule and dependency pair contains exactly two nonempty column-name strings.
  • CSV lines use printable ASCII characters. The total length of all input strings is at most 200000.
  • Every comma is a separator; quoted fields and embedded newlines are outside this exercise.

More Stripe Phone Screen questions

  • Split Tender Part 4 - RefundsOA · PHONE SCREEN · Seen Nov 2026
  • Merchant Payout Reserve CalculatorPHONE SCREEN · Seen Nov 2026
  • Parse Boolean Rule ExpressionsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Linked Merchants Within Two HopsPHONE SCREEN · Seen Nov 2026
  • Merchant Matching, Parts 1–2: Shared Fields and Weighted ThresholdsPHONE SCREEN · Seen Nov 2026
  • Business Account KYC Verification — Parts 1–5PHONE SCREEN · Seen Nov 2026
  • Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026
  • Invoice / Payment ReconciliationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesPHONE SCREEN · Seen Nov 2026
  • Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesPHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Resolve Variable Equations with Dependency ErrorsApplied Intuition · PHONE SCREENApplied Intuition interview questions
  • Evaluate Formulas with Cycle DetectionInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
  • Resolve Variable Equations with Dependency ErrorsMotive · PHONE SCREENMotive interview questions
  • Spreadsheet With Dependent CellsCharacter.AI · PHONE SCREEN
  • Spreadsheet Formula DependenciesAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Merge Event PreferencesAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Task Build Order and File-Change RerunsVanta · PHONE SCREEN
  • Video Cache Hit Rates from a CSV LogTubi · PHONE SCREEN

Interview reports that mention this question

  • Stripe New Grad Team Screen Interview: 10 Experiences
  • Stripe New Grad SWE Interviews: 17 Experiences (Part 1 of 2)

Stripe interview experiences

  • Stripe New Grad SWE OA and Phone Screen: 2 Experiences
  • Stripe Experienced SWE OA and Onsite Questions: 3 Experiences
  • Stripe SWE Intern Linked Merchants Team Screen: 1 Experience
  • Stripe OA: What It Tests (2026)
All Stripe interview questionsSee Stripe hiring insights
Saved
class Solution {
    public String[] validateCsv(String[] lines, String[][] referenceRules, String[][] dependencies) {
        // write your code here
    }
}
Checking account…