FastPrepFeature Flag Evaluation

Feature Flag Evaluation

CVS Health logoCVS Health● EasyFULLTIMEPHONE SCREEN

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 is false, 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 is userId % 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, and enabled, rolloutPercents and allowLists have the same length.
  • Flag names (in flagNames and queryFlags) are 1 to 20 lowercase English letters or underscores, and the names in flagNames are all different.
  • 0 <= rolloutPercents[i] <= 100
  • Each allow list has at most 20 different user ids.
  • User ids are integers from 0 to 10^9.
  • 1 <= queryFlags.length <= 1000 and queryUsers.length == queryFlags.length

More CVS Health problems

See CVS Health hiring insights
Saved
public boolean[] evaluateFeatureFlags(String[] flagNames, boolean[] enabled, int[] rolloutPercents, int[][] allowLists, String[] queryFlags, int[] queryUsers) {
    // Write your code here.
}
Checking account…