3

We are building the comment model for Reddit's new backend that supports their app. We have come up with the following Comment structure. The numbers on the right side are the Like counts for each comment.

- Comment uuid 1: (Root level comment)                   89
|-- Reply uuid 2 (First level reply comment).            150
    |-- Reply uuid 7 (Second level reply comment)        92
         |-- Reply uuid 8 (Third level reply comment)    40
|-- Reply uuid 3 (First reply comment)                   112
|-- Reply uuid 4 (First reply comment).                  1
    |-- Reply uuid 9 (Second level reply comment).       0
         |-- Reply uuid 10 (Third level reply comment).  3
|-- Reply uuid 5 (First reply comment)                   5
|-- Reply uuid 6 (First reply comment)                   10
    |-- Reply uuid 11 (Second level reply comment).      78
         |-- Reply uuid 12 (Third level reply comment)   200

Goal: Write an API to fetch the top 5 comments ordered by Like count for a given Root Level Comment. If the comment is a Second or Third Level Reply Comment, fetch the entire thread. The API should not return more than 5 comments at a time.

Eg.: 1st call by API -> returns comments 2, 3, 6, 11 & 12. 2nd call of API -> returns comments 7,8 & 5.

  1. How do you store the data in SQL? Assume a Comment has an ID, Comment Message, Like Count, Timestamp and Parent Comment ID.
  2. What does the API look like? Should there be one massive SQL query?
  • 1
    If “*[you] are building the comment model for Reddit's new backend that supports their app*”, wouldn’t both your questions be answered by Reddit’s existing SQL structure and API…???? Why would Stack Overflow be able to opine on this when there are likely already standards in place at Reddit that should inform these decisions on your behalf? – esqew Aug 14 '22 at 22:31
  • 1
    "*... that supports their app.*" Looks like a homework question. – aaron Aug 15 '22 at 04:49
  • No, this is an interview question. Any ideas on how to solve this? – – technophile Aug 21 '22 at 23:03
  • I feel like asking for help from SO for an interview question kind of defeats the purpose of the interview question and what you could gain from putting in more research effort on your own part :/ – rainbow.gekota Nov 12 '22 at 09:05

0 Answers0