FastPrepFeature Flags with Rules, Dependencies and Exposure
Problems/Feature Flags with Rules, Dependencies and Exposure

Feature Flags with Rules, Dependencies and Exposure

Perplexity AI logoPerplexity AI● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2026 report of a Perplexity onsite describes a multi-part coding round on feature flags, said to be in the same style as the company's well-known file-system question. The first part is matching flag rules against users. A later part makes rules depend on other flags. A further part adds tracking of which users have been exposed to a flag.

The report gives only that outline: no rule syntax, inputs or outputs. We chose these: flags have an on/off default and ordered rules. A rule has conditions on string attributes (equals, not equals, one of) and prerequisite flags that must be on. A missing attribute never satisfies equals or one of, and always satisfies not equals. The first matching rule wins. A rule's conditions are checked before its prerequisites, and prerequisites are checked left to right, stopping at the first one that is off. A flag that can reach itself through prerequisites uses its default. Every evaluated flag, including prerequisites, records the user as exposed, and EXPOSED counts distinct users. The work is a list of EVAL and EXPOSED operations whose results are returned in order.

Our version is about 70% the same as the reported question.

You are building a small feature-flag service. Every flag is either "on" or "off" for a user.

  • flags[i] = "name default", where default is on or off.
  • rules[i] = "flag|value|conditions|prerequisites". value is on or off. conditions is empty or a &-separated list of attr=value, attr!=value or attr~v1/v2/... (one of). prerequisites is empty or a comma-separated list of flag names. A flag's rules are used in the order they appear in rules.
  • users[i] = "userId|attr=value,attr=value,..." (the part after | may be empty).
  • ops[i] is "EVAL userId flag" or "EXPOSED flag".

Evaluating a flag for a user: if the flag can reach itself by following prerequisites (through any of its rules, directly or through other flags), return its default. Otherwise try its rules in order. A rule matches when every condition holds and then every prerequisite, evaluated left to right for the same user, is on; stop checking that rule at the first failure (conditions are checked before any prerequisite). Return the value of the first matching rule, or the default if no rule matches. A missing attribute makes = and ~ false and != true.

Exposure: whenever a flag is evaluated for a user (the requested flag or any prerequisite actually evaluated), that user is exposed to that flag. EXPOSED flag returns how many different users have been exposed to it so far, as a decimal string.

Return the results of all operations, in order.

Function

evaluateFlags(flags: String[], rules: String[], users: String[], ops: String[]) → String[]

Examples

Example 1

flags = ["new_checkout off"]rules = ["new_checkout|on|country=us&plan~pro/team|"]users = ["u1|country=us,plan=pro","u2|country=ca,plan=pro"]ops = ["EVAL u1 new_checkout","EVAL u2 new_checkout","EXPOSED new_checkout"]return = ["on","off","2"]

Part 1, rule matching. u1 is in the US on the pro plan, so the rule matches and the flag is on. u2 is in Canada, so the rule fails and the default off is used. Both users were evaluated, so 2 users are exposed.

Example 2

flags = ["base off","fancy off"]rules = ["base|on|plan=pro|","fancy|on||base"]users = ["a|plan=pro","b|plan=free"]ops = ["EVAL a fancy","EVAL b fancy","EVAL b base"]return = ["on","off","off"]

Part 2, dependencies. fancy is on only when its prerequisite base is on. base is on for pro users, so a gets on and b gets off for both flags.

Example 3

flags = ["x off","y on","z off"]rules = ["x|on||y","y|off||x","z|on|region!=eu|y"]users = ["u|region=us","v|region=eu","w|"]ops = ["EVAL u z","EXPOSED y","EVAL v z","EXPOSED z","EXPOSED x","EVAL w x","EXPOSED y"]return = ["on","1","off","2","0","off","1"]

Part 3, exposure, with a cycle. x and y require each other, so both always use their defaults (x off, y on). z is not on a cycle. For u, the condition holds and the prerequisite y is on, so z is on, and u is exposed to z and y. For v (in the EU) the condition fails, so y is not evaluated. The exposure counts are then y 1, z 2, x 0; evaluating x for w gives its default off.

Constraints

  • 1 <= flags.length <= 50
  • 0 <= rules.length <= 200
  • 1 <= users.length <= 100
  • 1 <= ops.length <= 3000
  • Flag names, user IDs, attribute names and attribute values use only lowercase letters, digits and _, are 1 to 20 characters long, and flag names and user IDs are unique.
  • Every string follows the formats above; a rule has at most 5 conditions and at most 5 prerequisites, and every flag or user it names exists.

More Perplexity AI interview questions

  • In-Memory Filesystem CommandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Sort Topic Names by Prefix and NumberONSITE INTERVIEW · Seen Oct 2026
  • Out-of-Order Bank Ledger BalancesOA · Seen Nov 2026
  • Resource Reconciler: Plan and Apply CreatesPHONE SCREEN · Seen Nov 2026
  • Agent Task Dependency TrackerPHONE SCREEN · Seen May 2026
  • LLM Provider Pool FailoverPHONE SCREEN · Seen Aug 2025

Similar questions at other companies

  • Invoice / Payment ReconciliationStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • In-Memory Vault File SystemHarvey · ONSITE INTERVIEWHarvey interview questions
  • Template Variable ExpansionGoogle · ONSITE INTERVIEWGoogle interview questions
  • JSON Path Lookup with Implicit Array WildcardsMongoDB · ONSITE INTERVIEWMongoDB interview questions
  • Generate Word Guess FeedbackAtlassian · ONSITE INTERVIEWAtlassian interview questions
  • Filesystem Hash TreeCursor · PHONE SCREEN · ONSITE INTERVIEWCursor interview questions
  • Stable Unique Column RenamesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Render a Comment HierarchyAmazon · ONSITE INTERVIEW
  • Most Frequent Call Path in Interleaved LogsRoblox · ONSITE INTERVIEWRoblox interview questions
All Perplexity AI interview questionsSee Perplexity AI hiring insights
Saved
class Solution {
    public String[] evaluateFlags(String[] flags, String[] rules, String[] users, String[] ops) {
        // Write your code here.
    }
}
Checking account…