Implement comment sorting and nesting

Read the full interview experience this question came from →

Quick Overview

This question evaluates skills in frontend data handling and UI behavior, including implementing sortable lists, maintaining user-selected sort field and direction across refreshes, constructing nested comment trees from flat parentId references, and filtering content while preserving descendant visibility.

Implement comment sorting and nesting

Company: Bobyard

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given mock comment data on the frontend. Each comment has: - `id`: unique comment ID - `userId`: author ID - `timestamp`: creation time - `content`: comment text - `parentId`: nullable parent comment ID Implement the frontend behavior for a comment UI: 1. Display comments sorted by either `timestamp` or `userId`. 2. Support both ascending and descending order. 3. Preserve the user's selected sort field and sort direction after a page refresh. 4. Build nested comments from the flat input using `parentId` only; do not change the backend. 5. Add a text filter on `content` so that only comments matching the filter and all of their descendants are shown. Unrelated branches must be hidden. You may assume the data is provided locally as mock data.

Overview: This question evaluates skills in frontend data handling and UI behavior, including implementing sortable lists, maintaining user-selected sort field and direction across refreshes, constructing nested comment trees from flat parentId references, and filtering content while preserving descendant visibility.

Read the full Bobyard Software Engineer interview experience this question came from

|Home/Coding & Algorithms/Bobyard
Bobyard logo
Bobyard
Apr 9, 2026
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
9
0

You are given mock comment data on the frontend. Each comment has:

  • id : unique comment ID
  • userId : author ID
  • timestamp : creation time
  • content : comment text
  • parentId : nullable parent comment ID

Implement the frontend behavior for a comment UI:

  1. Display comments sorted by either timestamp or userId .
  2. Support both ascending and descending order.
  3. Preserve the user's selected sort field and sort direction after a page refresh.
  4. Build nested comments from the flat input using parentId only; do not change the backend.
  5. Add a text filter on content so that only comments matching the filter and all of their descendants are shown. Unrelated branches must be hidden.

You may assume the data is provided locally as mock data.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...