AlgoMaster Logo
AlgoMasterBuild Sticky Feature-Flag Bucketseasy

Build Sticky Feature-Flag Buckets

easy

A percentage rollout should give one user a stable experience without storing an assignment for every account. A deterministic hash can place each user in a reproducible bucket that every application server calculates independently.

Design a FeatureFlagBucketer class:

  • FeatureFlagBucketer() creates a stateless bucketer.
  • int bucket(String userId) returns the user's stable bucket from 0 through 99.
  • boolean isEnabled(String userId, int rolloutPercent) returns whether the feature is enabled for that user.

Use this exact unsigned 32-bit polynomial hash:

The bucket is h % 100. A user is enabled exactly when:

Do not use a language's built-in string hash. Each call is independent and must produce the same result on every supported language.

Example 1:

Input:

Output:

Explanation: The users land in buckets 40, 17, 9, and 76. At a 50% rollout, only buckets below 50 are enabled.

Example 2:

Input:

Output:

Explanation: Hashing is deterministic, so these IDs always return the same three buckets without stored assignments.

Constraints

  • 1 <= userId.length <= 40
  • userId contains printable ASCII characters.
  • 0 <= rolloutPercent <= 100
  • Use the specified unsigned 32-bit polynomial hash.
  • At most 200 total method calls are made.
Hints

Loading...
CallReturns
new FeatureFlagBucketer()null
isEnabled("alice", 50)true
isEnabled("bob", 50)true
isEnabled("carol", 50)true
isEnabled("dave", 50)false

The four users land in buckets 40, 17, 9, and 76. Only the first three buckets are below 50.

Run checks these cases. Submit also runs a larger hidden set.