Feature Flag Evaluation
Problem statement
A feature-flag system decides whether a feature is on for a user. Flag i is named flagNames[i] and has three settings:
enabled[i]: a master switch. When it isfalse, the feature is off for everyone.allowLists[i]: user ids that always get the feature while the switch is on.rolloutPercents[i]: the percentage of other users who get it. A user's bucket isuserId % 100, and the user gets the feature when the bucket is less than the percentage.
For each query, decide whether flag queryFlags[j] is on for user queryUsers[j]. Check the rules in this order: a flag name that does not exist is off; a switched-off flag is off; a user on the allow list is on; otherwise the bucket rule decides.
Return the answers in query order.
Function
evaluateFeatureFlags(flagNames: String[], enabled: boolean[], rolloutPercents: int[], allowLists: int[][], queryFlags: String[], queryUsers: int[]) → boolean[]Examples
Example 1
flagNames = ["new_checkout","dark_mode"]enabled = [true,false]rolloutPercents = [30,100]allowLists = [[7],[5]]queryFlags = ["new_checkout","new_checkout","new_checkout","dark_mode","beta_search"]queryUsers = [1229,1250,7,5,1]return = [true,false,true,false,false]new_checkout is on with 30% rollout. User 1229 is in bucket 1229 % 100 = 29, which is below 30, so it is on. User 1250 is in bucket 50, so it is off. User 7 is on the allow list, so it is on, and bucket 7 would also pass. dark_mode is turned off, so it is off for everyone, even user 5 on its allow list. beta_search does not exist, so it is off.
Example 2
flagNames = ["pilot"]enabled = [true]rolloutPercents = [0]allowLists = [[42,1000000000]]queryFlags = ["pilot","pilot","pilot"]queryUsers = [42,43,1000000000]return = [true,false,true]With 0% rollout, only the allow-listed users 42 and 1000000000 get the feature. User 43 does not.
Constraints
1 <= flagNames.length <= 50, andenabled,rolloutPercentsandallowListshave the same length.- Flag names (in
flagNamesandqueryFlags) are 1 to 20 lowercase English letters or underscores, and the names inflagNamesare all different. 0 <= rolloutPercents[i] <= 100- Each allow list has at most 20 different user ids.
- User ids are integers from
0to10^9. 1 <= queryFlags.length <= 1000andqueryUsers.length == queryFlags.length