FastPrepStream Cluster Max and Median
Problems/Stream Cluster Max and Median

Stream Cluster Max and Median

Snap Inc. logoSnap Inc.● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Snap Inc. phone screen. The report describes data coming in as a stream and being put into an existing or new stored cluster. You read each cluster's maximum, make reads and writes fast, and answer a follow-up about the median. We chose the distance test against a cluster's representative, the operation strings, the cluster names, the tie rules, the exact median text, and the limits. Our version is about 67% the same as the reported question.

Process an integer data stream whose values are assigned to stored clusters. A cluster's representative is its first value and never changes.

  • ADD value: among representatives within maxDistance of value, choose the closest; break a distance tie by the smaller zero-based cluster identifier. If none qualifies, create a new cluster. Append the assigned cluster identifier.
  • MAX clusterId: append that cluster's maximum value, or INVALID for an unknown identifier.
  • MEDIAN clusterId: append the exact median, using an integer or an x.5 string, or INVALID for an unknown identifier.

Return one string for every operation in order.

Function

processClusterStream(maxDistance: int, operations: String[]) → String[]

Examples

Example 1

maxDistance = 3operations = ["ADD 10","ADD 12","ADD 20","ADD 17","MAX 0","MEDIAN 0","MAX 1","MEDIAN 1"]return = ["0","0","1","1","12","11","20","18.5"]

Ten and twelve form cluster 0. Twenty starts cluster 1, and seventeen joins it at distance three from its representative.

Example 2

maxDistance = 5operations = ["ADD 0","ADD 10","ADD 5","MEDIAN 0","MEDIAN 1","MAX 4"]return = ["0","1","0","2.5","10","INVALID"]

Value five ties both representatives and joins the smaller cluster identifier.

Constraints

  • 0 <= maxDistance <= 10^9.
  • 1 <= operations.length <= 5000.
  • Added values are signed 32-bit integers.
  • Every operation has one of the exact forms above.

More Snap Inc. interview questions

  • ID Allocator with Assign and ReleasePHONE SCREEN · Seen Nov 2026
  • Basic Calculator IIPHONE SCREEN · Seen Oct 2026
  • LRU Cache with Thread-Safety Follow-UpPHONE SCREEN · Seen Sep 2026
  • Smallest Range Covering Elements from K ListsPHONE SCREEN · Seen Sep 2026
  • Most Stones Removed with Same Row or ColumnPHONE SCREEN · Seen Sep 2026
  • Report Island Areas in Discovery OrderPHONE SCREEN · Seen Aug 2026
  • Render an Org Chart and Find Skip-Level PairsONSITE INTERVIEW · Seen Nov 2026
  • Peak of an Increasing-Then-Decreasing ArrayONSITE INTERVIEW · Seen Oct 2026
  • Number of Closed IslandsONSITE INTERVIEW · Seen Oct 2026
  • Radar Barrier CrossingONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Query Weekly Store Opening HoursApple · PHONE SCREENApple interview questions
  • Interview Slot BookingTrueFoundry · PHONE SCREEN
  • Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
  • Credit Accounts with Scheduled TransfersAirbnb · OAAirbnb interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Log Analyzer: Busiest Service in a Rolling WindowByteDance · PHONE SCREENByteDance interview questions
  • Consistent-Hash Packet RouterAmazon · PHONE SCREEN
  • Secret Number Search with One-Call-Delayed FeedbackOpenAI · PHONE SCREENOpenAI interview questions
  • Top K Pins with Insert and QueryPinterest · PHONE SCREENPinterest interview questions
  • Alert Engine with a Repeat IntervalChronosphere · PHONE SCREEN

Interview reports that mention this question

  • Snap AI Coding Interview, Experienced SWE and MLE: 4 Experiences

Snap Inc. interview experiences

  • Snap Experienced MLE Onsite Interview Questions: 1 Experience
  • Snap Experienced MLE Virtual Onsite: 1 Experience
All Snap Inc. interview questionsSee Snap Inc. hiring insights
Saved
class Solution {
    public String[] processClusterStream(int maxDistance, String[] operations) {
        // Write your code here.
    }
}
Checking account…