FastPrepPaginate Retained Conversation History
Problems/Paginate Retained Conversation History

Paginate Retained Conversation History

Sierra logoSierra● EasyNEW GRADFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two reports describe this Sierra phone screen, where conversation-history pagination was the first of three related parts. The earlier one asks for reading a conversation's history page by page, in order and without repeating or losing messages, and recalls trimming the oldest messages once a limit is passed. The newer one explains that the pages come from an API whose next cursor is followed until no conversation is left, inside a short hands-on session built on existing classes.

Neither report gives the data format, the stop marker or limits. We chose these. Each page is given as its cursor, its next cursor and its messages. An empty next cursor ends the chain. Pages are listed out of order. Every page has at least one message. The kept history is the newest historyLimit messages. The answer lists them from oldest to newest.

Our version is about 85% the same as the reported questions.

Interview-style brief

A conversation-history API returns messages one page at a time. Each page holds some messages and the cursor of the next page. Starting from the first cursor, keep following the next cursor until no pages are left, and keep only the most recent part of the history.

Rules

Each element of pages describes one page. pages[i][0] is the page's own cursor, pages[i][1] is the cursor of the next page, and the remaining entries are the page's messages from oldest to newest. An empty next cursor "" marks the last page. The pages are listed in no particular order, so follow the cursors rather than the array order.

Start with the page whose cursor is startCursor, read its messages, then move to the page named by its next cursor, and continue until you have read the last page. Messages on later pages are newer than messages on earlier pages.

While reading, keep at most historyLimit messages: whenever the history grows past the limit, drop the oldest message. Return the kept messages from oldest to newest. Each kept message appears exactly once, and messages with the same text are still separate messages.

Function

paginateConversationHistory(pages: String[][], startCursor: String, historyLimit: int) → String[]

Examples

Example 1

pages = [["c2","c3","m3","m4"],["c1","c2","m1","m2"],["c3","","m5"]]startCursor = "c1"historyLimit = 4return = ["m2","m3","m4","m5"]

Following the cursors from c1 reads the pages in the order c1, c2, c3, even though they are listed differently. That gives m1 through m5. Only 4 messages may be kept, so the oldest one, m1, is dropped.

Example 2

pages = [["start","","hi","How can I help?"]]startCursor = "start"historyLimit = 10return = ["hi","How can I help?"]

There is one page, and its next cursor is empty, so it is also the last page. Both messages fit under the limit of 10.

Example 3

pages = [["p","q","a"],["r","","c","d"],["q","r","b"]]startCursor = "p"historyLimit = 1return = ["d"]

The pages are read as p, q, r, giving a, b, c, d. With a limit of 1, only the newest message, d, is kept.

Constraints

  • 1 <= pages.length <= 500
  • 3 <= pages[i].length <= 42, so every page has its cursor, its next cursor and 1 to 40 messages.
  • Cursors contain 1 to 20 ASCII letters or digits, and the page cursors are distinct. Each next cursor is "" or the cursor of another page.
  • startCursor is a page cursor. Following next cursors from it visits every page exactly once and ends at the only page whose next cursor is "".
  • Every message has 1 to 50 printable ASCII characters.
  • 1 <= historyLimit <= 2000

More Sierra interview questions

  • Compact Conversation History by Token BudgetPHONE SCREEN · Seen Nov 2026
  • Compact Conversations by Unique ListingsPHONE SCREEN · Seen Oct 2026
  • Markdown Header ChunksPHONE SCREEN · Seen May 2026
  • Maximum Array ValueOA · Seen Oct 2026

Similar questions at other companies

  • Lazy Filter over a GeneratorSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
  • Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
  • Array-Backed Set Without Library CollectionsOde with Anthropic · PHONE SCREEN
  • Validate a Chess Bishop, Rook, or Queen MoveGlean · PHONE SCREENGlean interview questions
  • Count Distinct Underwriting PII ValuesAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
  • Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions
  • Match a Variadic Function SignatureConfluent · PHONE SCREENConfluent interview questions
  • Bounded IPv4 FilterAmazon · PHONE SCREEN
  • Partition and Group Values by ParityEPAM · PHONE SCREENEPAM interview questions
All Sierra interview questionsSee Sierra hiring insights
Saved
class Solution {
    public String[] paginateConversationHistory(String[][] pages, String startCursor, int historyLimit) {
        // Write your code here
    }
}
Checking account…