Reported September 2026
Databricksdesign

Customer Revenue with Direct Referrals

Reported by candidates from Databricks's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Databricks OA. Under 2s to a working solution.
Founder's read

Databricks reported this one in September 2026, and the input size is the first thing to read. With up to 5000 operations and k up to 5000, you might think an O(n log n) sort per query is fine. It is, barely, but that's not the point. The real work is keeping totals correct when a referral bumps an existing customer. This is a design and sorting problem dressed as a stream of operations. If you blank on the structure, StealthCoder is the invisible safety net running during the live OA, but the idea here is short enough to hold in your head.

The problem

Process a finite ordered sequence of customer-revenue operations. Customer IDs are assigned automatically as 0, 1, 2,....
["ADD", revenue] creates a customer whose total revenue starts at revenue.
["ADD_WITH_REFERRER", revenue, referrerId] creates a customer and immediately adds that initial revenue once to the existing direct referrer's total. The credit does not propagate to any earlier referrer.
["LOWEST_K", k, threshold] returns up to k customer IDs whose current totals are at least threshold, ordered by total revenue ascending and then customer ID ascending.
Return one integer array per operation: an addition returns a one-element array containing the new ID, and a query returns its ordered customer IDs.

Function
processCustomerRevenueOperations(operations: String[][]) → int[][]

Examples
Example 1
operations = [["ADD","100"],["ADD","40"],["LOWEST_K","2","0"]]
return = [[0],[1],[1,0]]
Customer 1 has total 40 and customer 0 has total 100, so the query returns them in that order.
Example 2
operations = [["ADD","50"],["ADD_WITH_REFERRER","20","0"],["ADD_WITH_REFERRER","30","0"],["LOWEST_K","3","25"],["ADD_WITH_REFERRER","40","1"],["LOWEST_K","4","0"]]
return = [[0],[1],[2],[2,0],[3],[2,3,1,0]]
The first two referrals raise customer 0 to 100. The last referral raises customer 1 from 20 to 60 but does not propagate to customer 0.
Example 3
operations = [["ADD","10"],["ADD","10"],["ADD_WITH_REFERRER","0","0"],["LOWEST_K","2","10"]]
return = [[0],[1],[2],[0,1]]
The threshold is inclusive. Customers 0 and 1 tie at total 10, so customer ID breaks the tie.

Constraints
1 <= operations.length <= 5000.
Every operation is well formed and uses one of the three documented names.
Every revenue and threshold is a decimal integer in [0, 1000000000].
Every referrer ID names a customer created by an earlier operation.
0 <= k <= 5000.
Every customer total fits a signed 64-bit integer.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Keep an array of totals indexed by customer ID. ADD appends a total and returns the new ID. ADD_WITH_REFERRER appends the new customer with its revenue, then adds that same revenue to the referrer's total once. No propagation up the chain, so there's no loop and no recursion. For LOWEST_K, filter customers with total >= threshold, sort by (total, id), and take the first k. At 5000 operations, that's about 5000 queries times a 5000 element sort, which is fine. The pitfalls are small but costly. The threshold is inclusive. A revenue of 0 is valid. Totals need a 64-bit type, so use long. Return a one-element array for every addition. k can be 0, so return an empty array. Parse the strings to integers before comparing, or you'll sort lexicographically. StealthCoder is your hedge if the live OA rattles you and you skip one of these edge cases.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Customer Revenue with Direct Referrals cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Databricks's OA.

Databricks reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Customer Revenue with Direct Referrals FAQ

How hard is Customer Revenue with Direct Referrals really?+

Easy to medium. There's no clever algorithm. It's a simulation with a sort. Most failures come from misreading the spec: propagating referral credit up the chain, forgetting the inclusive threshold, or sorting strings instead of numbers.

What's the trick to this Databricks OA question?+

Store totals in an array by ID and update the referrer once on ADD_WITH_REFERRER. For queries, filter by total >= threshold, sort by total then ID, and slice k. The constraints are small enough that a per-query sort passes.

Do I need a heap or balanced tree for LOWEST_K?+

Not at these limits. 5000 operations and 5000 customers means a sort per query is around 25 million element-steps times a log factor, which is workable. A sorted structure is an optimization you can mention, but it adds bug risk.

What edge cases break most solutions?+

Ties on total, which need the ID tiebreak. A threshold of 0 with revenue 0 customers. k larger than the number of qualifying customers. k equal to 0. And overflow, so use a 64-bit integer for totals since revenue sums can exceed 32 bits.

How do I prepare for this in 48 hours?+

Write it once from scratch with the three examples as tests. Parse strings to numbers, build the result array per operation, and check Example 2, where the referral to customer 1 doesn't touch customer 0. Then practice a few stream-of-operations design problems.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Databricks.

OA at Databricks?
Invisible during screen share
Get it