Problempayment preference resolver

Session: Sign in to solve

Solution.txt

Payment Preference Resolver

Problem

Design PaymentPreferenceResolver to choose a payment type by combining its supported transaction amount with the preference order configured for a transaction category.

Requirements

  • Amount eligibility. A payment type is eligible exactly when the transaction amount is less than or equal to its registered inclusive maximum.
  • Category preferences. defineCategoryPreference stores the supplied payment types from most to least preferred for that category.
  • Preferred eligible type. Selection returns the first eligible type in the category's configured order.
  • No eligible type. Selection returns the empty string when every configured type is excluded.

API

SignatureReturnsBehavior
PaymentPreferenceResolver()Not applicableCreates an empty resolver.
addPaymentType(paymentType: string, maximumAmount: integer)voidAdds one payment type and its amount limit.
defineCategoryPreference(category: string, paymentTypes: string[])voidAdds one category and its preference order.
selectPaymentType(amount: integer, category: string)stringResolves one payment type for the amount and category.

Examples

StepOperationResult
1addPaymentType("UPI", 2000)void
2addPaymentType("NET_BANKING", 10000)void
3defineCategoryPreference("GROCERIES", ["UPI", "NET_BANKING"])void
4defineCategoryPreference("TRAVEL", ["NET_BANKING", "UPI"])void
5selectPaymentType(1500, "GROCERIES")"UPI"
6selectPaymentType(5000, "GROCERIES")"NET_BANKING"
7selectPaymentType(1500, "TRAVEL")"NET_BANKING"
8selectPaymentType(15000, "TRAVEL")""

Constraints

  • At most 100 payment types, 1000 categories, and 100000 total method calls occur per testcase.
  • Payment type and category names contain from 1 through 64 Unicode code points and are compared exactly.
  • Amounts and maximum amounts are from 1 through 9000000000000000000.
  • A payment type is added once. A category is defined once, after all payment types are added.
  • Each category preference contains every registered payment type exactly once.
  • Selection uses a defined category. Inputs outside these preconditions are not judged.

Notes

Payment type and category names use the exact strings supplied during configuration. Calls are sequential, and concurrent access is outside scope.

PRIVATE WORKSPACE

Checking your session…

The statement is public. The editor, editorial, submissions, and saved work are private.