Code RoomUser variant rollout rules
EasyPrep Room Coding #4741

User variant rollout rules

CodingAlgorithms & data structuresEntry–Mid~16 min

A rollout service picks which build of the app each user sees. Every rule is written "conditions|variant", where conditions is either "*", which matches everyone, or a comma separated list of "key=value" pairs that must all hold. Every user is written "id;key=value;key=value": the first field is the user id, the rest are attributes, and a key written twice keeps its last value. A rule holds when each of its conditions names an attribute the user carries with exactly that value, compared as text. Rules are tried in the order given and the first one that holds decides the variant, even when a later rule is narrower. A user no rule holds for gets fallback. Return the variant for each user, in the order the users are given.

Implement
assign_rollout_variants(rules: list[str], users: list[str], fallback: str) → list[str]
Examples
in[["plan=pro,country=US|beta","plan=pro|early","country=US|us_only"],["u1;plan=pro;country=US","u2;plan=pro;country=CA","u3;plan=free;country=US","u4;plan=free;country=DE"],"control"]out["beta","early","us_only","control"]
in[["*|everyone","plan=pro|beta"],["u1;plan=pro","u2;plan=free"],"control"]out["everyone","everyone"]
in[["plan=pro|beta"],["u1;country=US","u2;plan=pro"],"control"]out["control","beta"]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 16 min
InputExpectedGot
[["plan=pro,country=US|beta","plan=pro|early","country=US|us_only"],["u1;plan=pro;country=US","u2;plan=pro;country=CA","u3;plan=free;country=US","u4;plan=free;country=DE"],"control"]["beta","early","us_only","control"]not run yetsample
[["*|everyone","plan=pro|beta"],["u1;plan=pro","u2;plan=free"],"control"]["everyone","everyone"]not run yetsample
[["plan=pro|beta"],["u1;country=US","u2;plan=pro"],"control"]["control","beta"]not run yetsample