← Questions
Decide which features a user sees
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Stripe's technical phone screen, last asked Nov 2023. It tests sorting, hash map and simulation.
Decide which product features one user sees. Each feature has an ID, a priority, an A/B-test flag, a list of allowed locations, and a list of features it conflicts with. Apply the eligibility rules, then resolve conflicts by priority.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
visible_features(user_id: int, location: str, features: list[str], opt_in: list[str], opt_out: list[str]) -> list[str]- Each feature row is
feature_id,priority,ab_test,locations,conflicts;locationsandconflictsare|-separated, andconflictsis-when empty. -
Eligible: the user's location is in the list, and either
ab_testis false or the user ID is even. - Opt-in skips only the A/B check; the location must still match. Opt-out makes a feature ineligible no matter what.
- Conflicts: visit eligible features from highest priority down (ties by input order) and keep each one that does not conflict with a feature already kept. A conflict listed by either feature counts for both.
- Return the kept feature IDs in input order.
- Each feature row is
Example
features = ["fast_pay,10,true,US|CA,legacy_pay",
"legacy_pay,5,false,US,fast_pay",
"eu_dashboard,8,false,EU,-"]
visible_features(4, "US", features, [], []) -> ["fast_pay"] # wins the conflict on priority
visible_features(3, "US", features[:2], ["fast_pay"], []) -> ["fast_pay"] # odd user, but opted in
visible_features(4, "US", features[:2], [], ["fast_pay"]) -> ["legacy_pay"] # fast_pay opted out
Constraints
- Up to 500 features with unique IDs. Comparisons are case-sensitive.
-
opt_inandopt_outlist known features and never overlap.
Clarifying questions
- Is the A/B group really "even user ID", or a hash of the user and the feature?
- Does opting in skip the location check too? (No.)
- If A conflicts with B but B does not list A, do they still conflict? (Yes.)
- Can a feature list itself as a conflict?
What a strong answer covers
- Parsing each row once into a small record; a symmetric conflict map built from both sides.
- Eligibility as one function with the opt-in and opt-out rules in a clear order.
- A stable sort by descending priority, then a greedy pass that keeps a set of chosen IDs.
- Returning the result in input order, not priority order.
- O(F log F + total conflicts) time.
- Tests for each rule, including a one-sided conflict and equal priorities.
Follow-ups
- Features can depend on other features (only shown if the parent is shown).
- Replace the even-ID rule with a stable hash bucket for percentage rollouts.
- Evaluate this for millions of users per second. What do you precompute?
Where it's asked
- Stripe · Technical phone screen · Last asked Nov 202360 min · One realistic task in parts, in a project editor (CoderPad project mode or HackerRank Projects) with several files and tests
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
