← 返回 stripe 的题目列表Business Account Data Verification
类型:online_judge
Problem: Business Account Data Verification
Stripe needs to verify whether a business account has provided all required information. Implement a validator that takes an account object and a list of rules, and returns the missing required fields.
Input Format
The input from stdin is a JSON object:
{
"account": { ... },
"rules": [
{
"when": { ... },
"requires": ["field.path", "nested.field.path"],
"one_of": [["field.a", "field.b"]]
}
]
}
Rule Semantics
Each rule contains:
when: an object describing when the rule applies.
The rule applies only if every path in when exists in account and equals the specified value.
If when is empty, the rule always applies.
requires: a list of field paths that must exist and be non-empty when the rule applies.
one_of: a list of field groups. For each group, at least one field in the group must exist and be non-empty.
Field paths use . for nested access, for example:
business.name
representative.first_name
company.tax_id
Array wildcard paths must also be supported:
owners[].first_name
This means:
owners must exist and be a non-empty array;
every element in the array must contain a non-empty first_name field.
Non-empty Definition
A field exists and is non-empty if:
the path can be found in account;
the value is not null;
if the value is a string, it is not "";
if the value is a list, it is not empty.
Output Format
Print missing fields, one per line, sorted lexicographically.
For a failed one_of group, print:
one_of(field1|field2|...)
If there are no missing fields, print:
VERIFIED
Constraints
1 <= rules.length <= 200
requires.length <= 50 per rule
one_of.length <= 20 per rule
each field path has length at most 100
total number of JSON nodes in account is at most 10^4
Example
Input:
{
"account": {
"country": "US",
"business_type": "company",
"business": {"name": "Acme"},
"company": {"tax_id": ""},
"representative": {"first_name": "Ann"}
},
"rules": [
{
"when": {"country": "US", "business_type": "company"},
"requires": ["business.name", "company.tax_id", "representative.first_name", "representative.last_name"],
"one_of": [["company.tax_id", "company.registration_number"]]
}
]
}
Output:
company.tax_id
one_of(company.tax_id|company.registration_number)
representative.last_name
Example
Input
{"account":{"country":"US","business_type":"company","business":{"name":"Acme"},"company":{"tax_id":""},"representative":{"first_name":"Ann"}},"rules":[{"when":{"country":"US","business_type":"company"},"requires":["business.name","company.tax_id","representative.first_name","representative.last_name"],"one_of":[["company.tax_id","company.registration_number"]]}]}
Output
company.tax_id
one_of(company.tax_id|company.registration_number)
representative.last_name