Resolve Visible User Features
Problem statement
You are given one user and a list of product features. Each feature row has the form featureId,priority,abTest,locations,conflicts.
priorityis an integer.abTestistrueorfalse.locationsis a|-separated list of allowed locations.conflictsis a|-separated list of feature IDs, or-when there are none.
A feature is initially eligible when the user's location appears in its location list and either its A/B test is disabled or the user's ID is even. An explicitly opted-in feature bypasses only the A/B-test check; it must still allow the user's location. An explicitly opted-out feature is never eligible, even when every other rule passes.
Resolve conflicts among eligible features in descending priority order. Break equal-priority ties by the feature's input position. Select a feature only when it does not conflict with an already selected feature. Treat a conflict named by either feature as a conflict between both features. Return the selected feature IDs in their original input order.
Function
resolveVisibleFeatures(userId: int, location: String, features: String[], optIn: String[], optOut: String[]) → String[]Examples
Example 1
userId = 4location = "US"features = ["fast_pay,10,true,US|CA,legacy_pay","legacy_pay,5,false,US,fast_pay","eu_dashboard,8,false,EU,-"]optIn = []optOut = []return = ["fast_pay"]Both US payment features are eligible, but they conflict. fast_pay has the higher priority, so only it remains visible.
Example 2
userId = 3location = "US"features = ["fast_pay,10,true,US|CA,legacy_pay","legacy_pay,5,false,US,fast_pay"]optIn = ["fast_pay"]optOut = []return = ["fast_pay"]The odd user would normally fail the A/B-test rule, but the opt-in bypasses that check. The higher-priority feature then wins the conflict.
Example 3
userId = 4location = "US"features = ["fast_pay,10,true,US|CA,legacy_pay","legacy_pay,5,false,US,fast_pay"]optIn = []optOut = ["fast_pay"]return = ["legacy_pay"]The explicit opt-out removes fast_pay, leaving the otherwise eligible legacy feature.
Constraints
1 <= features.length <= 500.- Feature IDs are unique non-empty ASCII strings without
,,|, or whitespace. - Every feature row has exactly five comma-separated fields and a valid integer priority.
- Every location list is non-empty;
conflictsis either-or a list of known feature IDs. optInandoptOutcontain unique known feature IDs and are disjoint.- All string comparisons are case-sensitive.