Merge Two Sorted Lark Message Timelines Into One Buffer In Place

Last updated: November 29, 2026

Quick Overview

Lark keeps a buffer of m locally cached messages sorted by timestamp with n empty slots at the end; merge n newly synced sorted messages into it in place so the full buffer stays sorted.

ByteDance
Coding & Algorithms
Software Engineer
ByteDance
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Lark keeps a buffer of m locally cached messages sorted by timestamp with n empty slots at the end; merge n newly synced sorted messages into it in place so the full buffer stays sorted.

A quick phone-screen problem for client and backend engineers on Lark (Feishu), where offline messages must be merged with the local cache without extra allocation on mobile. The interviewer checks that you fill from the back to avoid overwriting unread elements and keep ties stable.

What the Interviewer Expects
  • Recognize that merging from the front overwrites data
  • Use three pointers filling from the end
  • Only loop while synced messages remain
  • Keep local messages before synced ones on equal timestamps, and say so
  • State O(m + n) time and O(1) extra space
Key Topics to Cover
two pointers
in-place merge
stability
arrays
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if duplicate message IDs can appear in both lists?
  • How would you merge k sorted timelines from different devices?
  • What changes if the cache is a linked list?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list a of length m + n whose first m entries are (timestamp, message) sorted ascending, and list b of n sorted entries. Output: a fully sorted, modified in place. Ties should keep the local mes...

High-Level Design

Fill a from the end. Pointer i walks the cached part backward, j walks b backward, and k marks the next slot to write. At each step write the larger timestamp to a[k]. When b is exhausted we can stop,...


Submit Your Answer
Markdown supported