Engineering With Java

Engineering With Java

Java Coding Problem - Merchant Feature Flag Analytics

Suraj Mishra's avatar
Suraj Mishra
Dec 18, 2025
∙ Paid

Context

You are working on a payments platform that supports thousands of merchants.
For each merchant, we can enable or disable a set of product features — such as:

  • INSTANT_PAYOUTS

  • MULTI_CURRENCY

  • FRAUD_PROTECTION

  • BETA_DASHBOARD

  • ADVANCED_REPORTING

The platform stores feature flags per merchant in a database table:

merchant_id | feature_name        | enabled
---------------------------------------------
M101        | INSTANT_PAYOUTS     | 1
M101        | FRAUD_PROTECTION    | 0
M101        | MULTI_CURRENCY      | 1
M101        | BETA_DASHBOARD      | 1
M102        | INSTANT_PAYOUTS     | 0
...

Where:

  • enabled = 1 → feature is active

  • enabled = 0 → feature is inactive

Your task is to build logic that helps the platform understand how many features each merchant has enabled vs disabled.

For a given merchant_id, compute:

  1. Total number of enabled features

  2. Total number of disabled features

  3. (Optional) Return a summary object with the counts


Input

You are given:

class FeatureFlag {
    String merchantId;
    String featureName;
    int enabled; // 1 or 0
}

And a method:

List<FeatureFlag> getFeatureFlagsForMerchant(String merchantId);

Output

Design a method:

FeatureFlagSummary summarize(String merchantId);

Where:

record FeatureFlagSummary(
    String merchantId,
    int enabledCount,
    int disabledCount
) {}

Requirements

  • Count how many feature flags for the merchant have enabled = 1

  • Count how many feature flags have enabled = 0

  • Return these counts in a summary object


Example

Input:

Merchant M101 has flags:

[1, 0, 1, 1]

Output:

{
  merchantId: “M101”,
  enabledCount: 3,
  disabledCount: 1
}

📢 Consider becoming a paid subscriber for as low as $2.5/mo (with an annual subscription) and support the work :)

Not convinced? Check out the details of the past work


Solution

User's avatar

Continue reading this post for free, courtesy of Suraj Mishra.

Or purchase a paid subscription.
© 2026 Suraj Mishra · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture