FastPrepDigit-Coded Card Validation
Problem · Array

Digit-Coded Card Validation

Learn this problem
MediumCapital One logoCapital OneFULLTIMEONSITE INTERVIEW

Problem statement

You are given three parallel arrays describing digit-coded payments: cardNumbers, transactionIds, and integer-dollar amounts. Return one validity flag per payment in input order.

Indices are zero-based from the left. In each 16-digit card number, index 13 is 1 for multi-use and 0 for one-time, index 14 is 0 for Visa and 1 for Master, and index 15 is 1 for merchant-bound and 0 for unbound. In each 8-digit transaction ID, index 6 is 1 for charge and 0 for authorization, while index 7 is 1 for online and 0 for offline.

A Visa payment is valid when the card is merchant-bound and multi-use, or when the transaction is an online charge below 100. A Master payment is valid when an unbound card has amount below 100, or when a merchant-bound card has amount above 100. These comparisons are strict, so amount 100 satisfies neither amount rule.

Function

validatePayments(cardNumbers: String[], transactionIds: String[], amounts: int[]) → boolean[]

Examples

Example 1

cardNumbers = ["1234567891011111"]transactionIds = ["50781100"]amounts = [150]return = [true]

The card's final three flags are 111: multi-use, Master, and merchant-bound. A merchant-bound Master payment above 100 is valid.

Example 2

cardNumbers = ["1234567890123101","1234567890123000","1234567890123010","1234567890123011"]transactionIds = ["12345600","12345611","12345600","12345611"]amounts = [500,99,99,100]return = [true,true,true,false]

The first Visa card is merchant-bound and multi-use. The second is an online Visa charge below 100. The third is an unbound Master payment below 100. The last is merchant-bound Master at exactly 100, which matches neither strict amount rule.

Example 3

cardNumbers = ["1234567890123000"]transactionIds = ["12345601"]amounts = [50]return = [false]

This is an online Visa authorization, not a charge, and the card is neither merchant-bound nor multi-use.

Constraints

  • 1 <= cardNumbers.length = transactionIds.length = amounts.length <= 100000.
  • Every card number contains exactly 16 decimal digits, and every transaction ID contains exactly 8 decimal digits.
  • Each encoded flag at card indices 13, 14, and 15 and transaction indices 6 and 7 is either 0 or 1.
  • 1 <= amounts[i] <= 1000000000.

More Capital One problems

drafts saved locally
public boolean[] validatePayments(String[] cardNumbers, String[] transactionIds, int[] amounts) {
    // Write your code here.
}
cardNumbers["1234567891011111"]
transactionIds["50781100"]
amounts[150]
expected[true]
checking account