FastPrepCompact Conversations by Unique Listings
Problems/Compact Conversations by Unique Listings

Compact Conversations by Unique Listings

Sierra logoSierra● MediumNEW GRADFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Sierra phone screen. The report does not say what kind of container to return or how to handle duplicates inside one conversation. Our version is about 95% the same as the reported question.

Special thanks: 🌷 A special thank you to a lovely, amazing fren for sharing that this question appeared again on October 29, 2026! ( ᴗ͈ˬᴗ͈)ഒ 🩵

You are given an ordered array conversations. Each conversation contains listing identifiers, and an identifier may appear in several conversations or more than once in one conversation.

While the retained history contains more than maxUniqueListings distinct identifiers, remove the oldest entire conversation. Use identifier occurrence counts so an identifier stops contributing to the distinct total only after its final retained occurrence is removed.

After removing enough conversations, return the distinct identifiers from the retained conversations in first-appearance order. Include each identifier exactly once.

Function

compactUniqueListings(conversations: String[][], maxUniqueListings: int) → String[]

Examples

Example 1

conversations = [["a","b","c"],["b","c","d"],["e"]]maxUniqueListings = 4return = ["b","c","d","e"]

All conversations contain five distinct identifiers. Removing the oldest conversation deletes the final occurrence of "a", leaving the first-appearance order ["b","c","d","e"].

Example 2

conversations = [["x","x"],["x"]]maxUniqueListings = 1return = ["x"]

The history already contains one distinct identifier, so no conversation is removed. Repeated occurrences produce one output entry.

Example 3

conversations = [["a"],["b"],["a"]]maxUniqueListings = 1return = ["a"]

Removing the first conversation does not remove "a" from the distinct set because it appears later. Removing the second conversation deletes "b", leaving only "a".

Constraints

  • 0 <= conversations.length <= 10^5
  • The total number of listing occurrences across all conversations is at most 10^5.
  • Every listing identifier is a non-empty ASCII string.
  • 0 <= maxUniqueListings <= 10^5

More Sierra interview questions

  • Compact Conversation History by Token BudgetPHONE SCREEN · Seen Nov 2026
  • Paginate Retained Conversation HistoryPHONE SCREEN · Seen Nov 2026
  • Markdown Header ChunksPHONE SCREEN · Seen May 2026
  • Maximum Array ValueOA · Seen Oct 2026

Similar questions at other companies

  • Shortest Window by Distinct-Value SumOracle · PHONE SCREENOracle interview questions
  • Find Word-Multiset WindowsAmazon · PHONE SCREEN
  • Transcript Window MetricsSesame · PHONE SCREEN
  • Invalid Transactions in Time OrderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Count Equal-Offset Pairs Within an Index DistanceGoogle · PHONE SCREENGoogle interview questions
  • Detect Security Attacks from Network LogsFireworks AI · PHONE SCREEN
  • Smallest Range Covering Elements from K ListsSnap Inc. · PHONE SCREENSnap Inc. interview questions
  • Count Zero Request ServersSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Count Belt Sections With K Fruit Pairs (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
  • Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
All Sierra interview questionsSee Sierra hiring insights
Saved
class Solution {
    public String[] compactUniqueListings(String[][] conversations, int maxUniqueListings) {
        // Write your code here
    }
}
Checking account…