FastPrepRole Co-occurrences Within a Period
Problems/Role Co-occurrences Within a Period

Role Co-occurrences Within a Period

WhatNot logoWhatNot● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Whatnot new grad Karat screen as the second question. The task was to find which two roles one performer sang close together in time, and how often that happened. The task and all test lists are the same as reported.

The report prints the result as a map from each role to its partner counts, in no fixed order. Here, you return one row per role, sorted by name, with each partner and its count. The report does not say what happens when a singer repeats a role, so each singer sings a role at most once here. It gives no size limits, so lists here have at most 1000 entries.

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

Given a list of performances, where each entry is [singer, role, year], and an integer period, return for every role the other roles that co-occurred with it and how many times.

Two roles co-occur when the same singer sang both of them in years that are at most period years apart (the limit is inclusive). Roles sung by different singers never co-occur. If several singers sang the same pair of roles within the period, each of them adds 1 to that pair's count.

Return one row per distinct role, sorted by role name in plain character-code (ASCII) order, so uppercase letters come before lowercase ones. A row starts with the role, followed by each co-occurring role and its count as a string, with the partner roles sorted the same way. A role with no co-occurrences still gets a row that holds only its name.

Function

cooccurrences(performances: String[][], period: int) → List<List<String>>

Examples

Example 1

performances = [["Alice","Role_A","2010"],["Alice","Role_B","2013"],["Alice","Role_C","2016"]]period = 3return = [["Role_A","Role_B","1"],["Role_B","Role_A","1","Role_C","1"],["Role_C","Role_B","1"]]

Alice sang Role_A and Role_B three years apart, and Role_B and Role_C three years apart. Role_A and Role_C are six years apart, which is more than 3.

Example 2

performances = [["Alice","Role_A","2010"],["Alice","Role_B","2013"],["Alice","Role_C","2016"]]period = 6return = [["Role_A","Role_B","1","Role_C","1"],["Role_B","Role_A","1","Role_C","1"],["Role_C","Role_A","1","Role_B","1"]]

With a period of 6, all three of Alice's roles are close enough, so every pair counts once.

Example 3

performances = [["Daphne","Role_D","2013"],["Alice","Role_A","2010"],["Alice","Role_B","2013"],["Alice","Role_C","2016"]]period = 3return = [["Role_A","Role_B","1"],["Role_B","Role_A","1","Role_C","1"],["Role_C","Role_B","1"],["Role_D"]]

Daphne sang only Role_D, so it has no partner roles but still gets its own row.

Example 4

performances = [["Alice","Role_E","2015"],["Bob","Role_F","2015"],["Charles","Role_G","2015"],["Daphne","Role_D","2010"],["Alice","Role_H","2016"],["Bob","Role_I","2016"],["Charles","Role_J","2017"],["Eric","Role_F","2019"],["Eric","Role_I","2017"]]period = 3return = [["Role_D"],["Role_E","Role_H","1"],["Role_F","Role_I","2"],["Role_G","Role_J","1"],["Role_H","Role_E","1"],["Role_I","Role_F","2"],["Role_J","Role_G","1"]]

Bob sang Role_F and Role_I one year apart, and Eric sang the same two roles two years apart, so that pair counts 2. Role_D has no partner.

Constraints

  • 1 <= performances.length <= 1000
  • performances[i].length == 3
  • singer and role are non-empty strings of letters, digits and underscores, at most 20 characters long.
  • year is a four-digit year from "1900" to "2100".
  • 0 <= period <= 200
  • A singer sings the same role at most once in performances.

More WhatNot Phone Screen questions

  • Merge Sorted Squares of Two ArraysPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Adjacent Pair and Run RemovalPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • User Journey Paths from a Log StreamPHONE SCREEN · Seen Nov 2026
  • Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
  • Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
  • Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
  • Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
  • Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Longest Consecutive SequenceJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
  • Top K Frequent Elements with a Recency TiebreakSwiggy · PHONE SCREEN
  • Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
  • Group AnagramsWorkday · PHONE SCREEN
  • Build a Task and Subtask HierarchyStripe · PHONE SCREENStripe interview questions
  • Find All Points Within a RadiusGoogle · PHONE SCREENGoogle interview questions
  • Resource Reconciler: Plan and Apply CreatesPerplexity AI · PHONE SCREENPerplexity AI interview questions

Interview reports that mention this question

  • Whatnot interviews · October 2025

WhatNot interview experiences

  • Whatnot OA · 2024
  • Whatnot OA · November 2023
  • Whatnot interviews · November 2023
  • Whatnot interviews · February 2024
  • Whatnot interviews · March 2024
All WhatNot interview questionsSee WhatNot hiring insights
Saved
class Solution {
    public List<List<String>> cooccurrences(String[][] performances, int period) {
        
    }
}
Checking account…