TikTok OA 面试题解析:Fetch and Render Questions(按分类分组统计)

13次阅读
没有评论

Fetch and Render Questions

Question description

There is an API that can return question data:

https://664353ed6c6a6565870698da.mockapi.io/api/test/questions

Response data:

[
  {
    id: "sign-up-form",
    name: "Sign-Up Form",
    category: "HTML"
  },
  ...
]

Then we have another API:

https://664353ed6c6a6565870698da.mockapi.io/api/test/submissions

Return data like this:

[
  {
    questionId: "Sign-Up Form",
    status: "CORRECT"
  },
  {
    questionId: "throttle",
    status: "INCORRECT"
  }
]

Requirements:

  • Render the questions by different group.
  • Show every group’s totalCount and correctCount.

Example:

HTML (2/4): Sign-Up Form, Div Tags

这道题要求你先分别拉取题目列表和提交记录,再按题目分类进行分组展示,并统计每个分组的总题数和正确题数。核心做法通常是用哈希表或字典把题目按 category 归类,再用另一个映射快速判断某道题是否在 submissions 中答对,最后按分类输出类似“HTML (2/4)”这样的结果。实现时要注意题目名称与提交记录的对应关系,以及正确率统计的边界情况。

正文完
 0