Problem · Design

Corporate Card Expense Rules

Learn this problem
MediumRipplingPHONE SCREEN

Problem statement

Evaluate corporate-card expenses against individual-expense and whole-trip policies.

Expense Format

Each row is [expenseId, tripId, amountUsd, expenseType, vendorType, vendorName]. Amounts are non-negative integer USD values. IDs and categorical values are case-sensitive.

Policy Rules

  1. RESTAURANT_LIMIT: an expense with vendorType = RESTAURANT may not exceed $75.
  2. NO_AIRFARE: an expense with expenseType = AIRFARE is not allowed.
  3. NO_ENTERTAINMENT: an expense with expenseType = ENTERTAINMENT is not allowed.
  4. EXPENSE_LIMIT: no individual expense may exceed $250.
  5. TRIP_LIMIT: the sum of all expenses on one trip may not exceed $2000.
  6. MEAL_LIMIT: the sum of expenses with expenseType = MEAL on one trip may not exceed $200.

Output

Return one row per expense in input order. The first value is the expense ID. Append every violated rule code in the policy order above. If the expense violates no rule, return only its ID.

A trip-level violation is attached to every expense belonging to that trip.

Interviewer follow-ups

The interviewer asked candidates to design the rule API so new per-expense and per-trip rules could be added without rewriting the evaluator. Reports also mention discussing validation order, rule composition, and how the return model should expose multiple violations.

Function

evaluateExpenseRules(expenses: String[][]) → String[][]

Examples

Example 1

expenses = [["e1","trip1","80","MEAL","RESTAURANT","Bistro"],["e2","trip1","130","MEAL","CAFE","Coffee"],["e3","trip2","300","AIRFARE","AIRLINE","Sky"]]return = [["e1","RESTAURANT_LIMIT","MEAL_LIMIT"],["e2","MEAL_LIMIT"],["e3","NO_AIRFARE","EXPENSE_LIMIT"]]

Trip 1 spends $210 on meals, so both trip expenses receive MEAL_LIMIT. Expense e1 also exceeds the restaurant cap. Expense e3 is airfare and exceeds $250.

Example 2

expenses = [["a","trip9","1000","LODGING","HOTEL","North"],["b","trip9","1100","LODGING","HOTEL","South"],["c","trip10","50","MEAL","RESTAURANT","Deli"]]return = [["a","EXPENSE_LIMIT","TRIP_LIMIT"],["b","EXPENSE_LIMIT","TRIP_LIMIT"],["c"]]

Trip 9 totals $2100, and both expenses also exceed the individual limit. Expense c passes every rule.

Constraints

  • 1 <= expenses.length <= 100000
  • Each expenseId is unique.
  • amountUsd is a non-negative integer string.

More Rippling problems

drafts saved locally
public String[][] evaluateExpenseRules(String[][] expenses) {
  // write your code here
}
expenses[["e1","trip1","80","MEAL","RESTAURANT","Bistro"],["e2","trip1","130","MEAL","CAFE","Coffee"],["e3","trip2","300","AIRFARE","AIRLINE","Sky"]]
expected[["e1", "RESTAURANT_LIMIT", "MEAL_LIMIT", "e2", "MEAL_LIMIT", "e3", "NO_AIRFARE", "EXPENSE_LIMIT"]]
checking account