mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-12-16 23:52:34 +08:00
99 lines
21 KiB
JSON
99 lines
21 KiB
JSON
{
|
||
"data": {
|
||
"question": {
|
||
"questionId": "4169",
|
||
"questionFrontendId": "3764",
|
||
"categoryTitle": "Database",
|
||
"boundTopicId": 3848456,
|
||
"title": "Most Common Course Pairs",
|
||
"titleSlug": "most-common-course-pairs",
|
||
"content": "<p>Table: <code>course_completions</code></p>\n\n<pre>\n+-------------------+---------+\n| Column Name | Type | \n+-------------------+---------+\n| user_id | int |\n| course_id | int |\n| course_name | varchar |\n| completion_date | date |\n| course_rating | int |\n+-------------------+---------+\n(user_id, course_id) is the combination of columns with unique values for this table.\nEach row represents a completed course by a user with their rating (1-5 scale).\n</pre>\n\n<p>Write a solution to identify <strong>skill mastery pathways</strong> by analyzing course completion sequences among top-performing students:</p>\n\n<ul>\n\t<li>Consider only <strong>top-performing students</strong> (those who completed <strong>at least </strong><code>5</code><strong> courses</strong> with an <strong>average rating of </strong><code>4</code><strong> or higher</strong>).</li>\n\t<li>For each top performer, identify the <strong>sequence of courses</strong> they completed in chronological order.</li>\n\t<li>Find all <strong>consecutive course pairs</strong> (<code>Course A → Course B</code>) taken by these students.</li>\n\t<li>Return the <strong>pair frequency</strong>, identifying which course transitions are most common among high achievers.</li>\n</ul>\n\n<p>Return <em>the result table ordered by</em> <em>pair frequency in <strong>descending</strong> order</em> <em>and then by first course name and second course name in <strong>ascending</strong> order</em>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>Input:</strong></p>\n\n<p>course_completions table:</p>\n\n<pre class=\"example-io\">\n+---------+-----------+------------------+-----------------+---------------+\n| user_id | course_id | course_name | completion_date | course_rating |\n+---------+-----------+------------------+-----------------+---------------+\n| 1 | 101 | Python Basics | 2024-01-05 | 5 |\n| 1 | 102 | SQL Fundamentals | 2024-02-10 | 4 |\n| 1 | 103 | JavaScript | 2024-03-15 | 5 |\n| 1 | 104 | React Basics | 2024-04-20 | 4 |\n| 1 | 105 | Node.js | 2024-05-25 | 5 |\n| 1 | 106 | Docker | 2024-06-30 | 4 |\n| 2 | 101 | Python Basics | 2024-01-08 | 4 |\n| 2 | 104 | React Basics | 2024-02-14 | 5 |\n| 2 | 105 | Node.js | 2024-03-20 | 4 |\n| 2 | 106 | Docker | 2024-04-25 | 5 |\n| 2 | 107 | AWS Fundamentals | 2024-05-30 | 4 |\n| 3 | 101 | Python Basics | 2024-01-10 | 3 |\n| 3 | 102 | SQL Fundamentals | 2024-02-12 | 3 |\n| 3 | 103 | JavaScript | 2024-03-18 | 3 |\n| 3 | 104 | React Basics | 2024-04-22 | 2 |\n| 3 | 105 | Node.js | 2024-05-28 | 3 |\n| 4 | 101 | Python Basics | 2024-01-12 | 5 |\n| 4 | 108 | Data Science | 2024-02-16 | 5 |\n| 4 | 109 | Machine Learning | 2024-03-22 | 5 |\n+---------+-----------+------------------+-----------------+---------------+\n</pre>\n\n<p><strong>Output:</strong></p>\n\n<pre class=\"example-io\">\n+------------------+------------------+------------------+\n| first_course | second_course | transition_count |\n+------------------+------------------+------------------+\n| Node.js | Docker | 2 |\n| React Basics | Node.js | 2 |\n| Docker | AWS Fundamentals | 1 |\n| JavaScript | React Basics | 1 |\n| Python Basics | React Basics | 1 |\n| Python Basics | SQL Fundamentals | 1 |\n| SQL Fundamentals | JavaScript | 1 |\n+------------------+------------------+------------------+\n</pre>\n\n<p><strong>Explanation:</strong></p>\n\n<ul>\n\t<li><strong>User 1</strong>: Completed 6 courses with average rating 4.5 (qualifies as top performer)</li>\n\t<li><strong>User 2</strong>: Completed 5 courses with average rating 4.4 (qualifies as top performer)</li>\n\t<li><strong>User 3</strong>: Completed 5 courses but average rating is 2.8 (does not qualify)</li>\n\t<li><strong>User 4</strong>: Completed only 3 courses (does not qualify)</li>\n\t<li><strong>Course Pairs Among Top Performers</strong>:\n\t<ul>\n\t\t<li>User 1: Python Basics → SQL Fundamentals → JavaScript → React Basics → Node.js → Docker</li>\n\t\t<li>User 2: Python Basics → React Basics → Node.js → Docker → AWS Fundamentals</li>\n\t\t<li>Most common transitions: Node.js → Docker (2 times), React Basics → Node.js (2 times)</li>\n\t</ul>\n\t</li>\n</ul>\n\n<p>Results are ordered by transition_count in descending order, then by first_course in ascending order, and then by second_course in ascending order.</p>\n</div>\n",
|
||
"translatedTitle": "最常见的课程组合",
|
||
"translatedContent": "<p>表:<code>course_completions</code></p>\n\n<pre>\n+-------------------+---------+\n| Column Name | Type | \n+-------------------+---------+\n| user_id | int |\n| course_id | int |\n| course_name | varchar |\n| completion_date | date |\n| course_rating | int |\n+-------------------+---------+\n(user_id, course_id) 是此表中具有不同值的列的组合。\n每一行代表一个用户完成的课程及其评分(1-5 分)。\n</pre>\n\n<p>编写一个解决方案,通过分析顶尖学生完成课程的序列来识别 <strong>课程路径</strong>:</p>\n\n<ul>\n\t<li>只考虑 <strong>顶尖学生</strong>(完成 <strong>至少</strong> <code>5</code> <strong>门课程且平均评分</strong> <code>4</code> <strong>分或以上 </strong>的人)。</li>\n\t<li>对每个顶尖学生,确定他们按时间顺序完成的 <strong>课程序列</strong>。</li>\n\t<li>找出这些学生所学的所有 <strong>连续课程对 </strong>(<code>课程 A → 课程 B</code>)。</li>\n\t<li>返回课程对的频率,确定顶尖学生中最常见的课程路径。</li>\n</ul>\n\n<p>返回结果表,按课程对频率 <strong>降序</strong> 排列,若频率相同则按第一课程名称和第二课程名称 <strong>升序</strong> 排列。</p>\n\n<p>结果格式如下所示。</p>\n\n<p> </p>\n\n<p><strong class=\"example\">示例:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>输入:</strong></p>\n\n<p>course_completions 表:</p>\n\n<pre class=\"example-io\">\n+---------+-----------+------------------+-----------------+---------------+\n| user_id | course_id | course_name | completion_date | course_rating |\n+---------+-----------+------------------+-----------------+---------------+\n| 1 | 101 | Python Basics | 2024-01-05 | 5 |\n| 1 | 102 | SQL Fundamentals | 2024-02-10 | 4 |\n| 1 | 103 | JavaScript | 2024-03-15 | 5 |\n| 1 | 104 | React Basics | 2024-04-20 | 4 |\n| 1 | 105 | Node.js | 2024-05-25 | 5 |\n| 1 | 106 | Docker | 2024-06-30 | 4 |\n| 2 | 101 | Python Basics | 2024-01-08 | 4 |\n| 2 | 104 | React Basics | 2024-02-14 | 5 |\n| 2 | 105 | Node.js | 2024-03-20 | 4 |\n| 2 | 106 | Docker | 2024-04-25 | 5 |\n| 2 | 107 | AWS Fundamentals | 2024-05-30 | 4 |\n| 3 | 101 | Python Basics | 2024-01-10 | 3 |\n| 3 | 102 | SQL Fundamentals | 2024-02-12 | 3 |\n| 3 | 103 | JavaScript | 2024-03-18 | 3 |\n| 3 | 104 | React Basics | 2024-04-22 | 2 |\n| 3 | 105 | Node.js | 2024-05-28 | 3 |\n| 4 | 101 | Python Basics | 2024-01-12 | 5 |\n| 4 | 108 | Data Science | 2024-02-16 | 5 |\n| 4 | 109 | Machine Learning | 2024-03-22 | 5 |\n+---------+-----------+------------------+-----------------+---------------+\n</pre>\n\n<p><strong>输出:</strong></p>\n\n<pre class=\"example-io\">\n+------------------+------------------+------------------+\n| first_course | second_course | transition_count |\n+------------------+------------------+------------------+\n| Node.js | Docker | 2 |\n| React Basics | Node.js | 2 |\n| Docker | AWS Fundamentals | 1 |\n| JavaScript | React Basics | 1 |\n| Python Basics | React Basics | 1 |\n| Python Basics | SQL Fundamentals | 1 |\n| SQL Fundamentals | JavaScript | 1 |\n+------------------+------------------+------------------+\n</pre>\n\n<p><strong>解释:</strong></p>\n\n<ul>\n\t<li><strong>用户 1:</strong>完成了 6 门课程,平均分为 4.5(满足顶尖学生)</li>\n\t<li><strong>用户 2:</strong>完成了 5 门课程,平均分为 4.4(满足顶尖学生)</li>\n\t<li><strong>用户 3:</strong>完成了 5 门课程但平均得分为 2.8(不满足资格)</li>\n\t<li><strong>用户 4:</strong>只完成了 3 门课程(不满足资格)</li>\n\t<li><strong>顶尖学生的课程对:</strong>\n\t<ul>\n\t\t<li>用户 1:Python Basics → SQL Fundamentals → JavaScript → React Basics → Node.js → Docker</li>\n\t\t<li>用户 2:Python Basics → React Basics → Node.js → Docker → AWS Fundamentals</li>\n\t\t<li>最常见的路径:Node.js → Docker (2 次),React Basics → Node.js (2 次)</li>\n\t</ul>\n\t</li>\n</ul>\n\n<p>结果按 transition_count 降序排列,然后按 first_course 升序排列,再按 second_course 升序排列。</p>\n</div>\n",
|
||
"isPaidOnly": false,
|
||
"difficulty": "Hard",
|
||
"likes": 0,
|
||
"dislikes": 0,
|
||
"isLiked": null,
|
||
"similarQuestions": "[]",
|
||
"contributors": [],
|
||
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python3\": false, \"python\": false, \"javascript\": false, \"typescript\": false, \"csharp\": false, \"c\": false, \"golang\": false, \"kotlin\": false, \"swift\": false, \"rust\": false, \"ruby\": false, \"php\": false, \"dart\": false, \"scala\": false, \"elixir\": false, \"erlang\": false, \"racket\": false, \"cangjie\": false, \"bash\": false, \"html\": false, \"pythonml\": false, \"react\": false, \"vanillajs\": false, \"mysql\": false, \"mssql\": false, \"postgresql\": false, \"oraclesql\": false, \"pythondata\": false}",
|
||
"topicTags": [],
|
||
"companyTagStats": null,
|
||
"codeSnippets": [
|
||
{
|
||
"lang": "MySQL",
|
||
"langSlug": "mysql",
|
||
"code": "# Write your MySQL query statement below",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "MS SQL Server",
|
||
"langSlug": "mssql",
|
||
"code": "/* Write your T-SQL query statement below */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "PostgreSQL",
|
||
"langSlug": "postgresql",
|
||
"code": "-- Write your PostgreSQL query statement below",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Oracle",
|
||
"langSlug": "oraclesql",
|
||
"code": "/* Write your PL/SQL query statement below */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Pandas",
|
||
"langSlug": "pythondata",
|
||
"code": "import pandas as pd\n\ndef topLearnerCourseTransitions(course_completions: pd.DataFrame) -> pd.DataFrame:\n ",
|
||
"__typename": "CodeSnippetNode"
|
||
}
|
||
],
|
||
"stats": "{\"totalAccepted\": \"57\", \"totalSubmission\": \"101\", \"totalAcceptedRaw\": 57, \"totalSubmissionRaw\": 101, \"acRate\": \"56.4%\"}",
|
||
"hints": [],
|
||
"solution": null,
|
||
"status": null,
|
||
"sampleTestCase": "{\"headers\":{\"course_completions\":[\"user_id\",\"course_id\",\"course_name\",\"completion_date\",\"course_rating\"]},\"rows\":{\"course_completions\":[[1,101,\"Python Basics\",\"2024-01-05\",5],[1,102,\"SQL Fundamentals\",\"2024-02-10\",4],[1,103,\"JavaScript\",\"2024-03-15\",5],[1,104,\"React Basics\",\"2024-04-20\",4],[1,105,\"Node.js\",\"2024-05-25\",5],[1,106,\"Docker\",\"2024-06-30\",4],[2,101,\"Python Basics\",\"2024-01-08\",4],[2,104,\"React Basics\",\"2024-02-14\",5],[2,105,\"Node.js\",\"2024-03-20\",4],[2,106,\"Docker\",\"2024-04-25\",5],[2,107,\"AWS Fundamentals\",\"2024-05-30\",4],[3,101,\"Python Basics\",\"2024-01-10\",3],[3,102,\"SQL Fundamentals\",\"2024-02-12\",3],[3,103,\"JavaScript\",\"2024-03-18\",3],[3,104,\"React Basics\",\"2024-04-22\",2],[3,105,\"Node.js\",\"2024-05-28\",3],[4,101,\"Python Basics\",\"2024-01-12\",5],[4,108,\"Data Science\",\"2024-02-16\",5],[4,109,\"Machine Learning\",\"2024-03-22\",5]]}}",
|
||
"metaData": "{\"mysql\":[\"CREATE TABLE course_completions (\\n user_id INT,\\n course_id INT,\\n course_name VARCHAR(100),\\n completion_date DATE,\\n course_rating INT\\n)\"],\"mssql\":[\"CREATE TABLE course_completions (\\n user_id INT,\\n course_id INT,\\n course_name VARCHAR(100),\\n completion_date DATE,\\n course_rating INT\\n)\"],\"oraclesql\":[\"CREATE TABLE course_completions (\\n user_id NUMBER,\\n course_id NUMBER,\\n course_name VARCHAR2(100),\\n completion_date DATE,\\n course_rating NUMBER\\n)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"pythondata\":[\"course_completions = pd.DataFrame({\\n \\\"user_id\\\": pd.Series(dtype=\\\"int\\\"),\\n \\\"course_id\\\": pd.Series(dtype=\\\"int\\\"),\\n \\\"course_name\\\": pd.Series(dtype=\\\"string\\\"), # corresponds to SQL VARCHAR\\n \\\"completion_date\\\": pd.Series(dtype=\\\"datetime64[ns]\\\"), # corresponds to SQL DATE\\n \\\"course_rating\\\": pd.Series(dtype=\\\"Int64\\\") # corresponds to SQL INT (nullable)\\n})\"],\"postgresql\":[\"CREATE TABLE if not exists course_completions (\\n user_id INT,\\n course_id INT,\\n course_name VARCHAR(100),\\n completion_date DATE,\\n course_rating INT\\n)\"],\"manual\":true,\"database_schema\":{\"course_completions\":{\"user_id\":\"INT\",\"course_id\":\"INT\",\"course_name\":\"VARCHAR(100)\",\"completion_date\":\"DATE\",\"course_rating\":\"INT\"}}}",
|
||
"judgerAvailable": true,
|
||
"judgeType": "large",
|
||
"mysqlSchemas": [
|
||
"CREATE TABLE course_completions (\n user_id INT,\n course_id INT,\n course_name VARCHAR(100),\n completion_date DATE,\n course_rating INT\n)",
|
||
"Truncate table course_completions",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('1', '101', 'Python Basics', '2024-01-05', '5')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('1', '102', 'SQL Fundamentals', '2024-02-10', '4')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('1', '103', 'JavaScript', '2024-03-15', '5')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('1', '104', 'React Basics', '2024-04-20', '4')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('1', '105', 'Node.js', '2024-05-25', '5')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('1', '106', 'Docker', '2024-06-30', '4')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('2', '101', 'Python Basics', '2024-01-08', '4')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('2', '104', 'React Basics', '2024-02-14', '5')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('2', '105', 'Node.js', '2024-03-20', '4')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('2', '106', 'Docker', '2024-04-25', '5')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('2', '107', 'AWS Fundamentals', '2024-05-30', '4')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('3', '101', 'Python Basics', '2024-01-10', '3')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('3', '102', 'SQL Fundamentals', '2024-02-12', '3')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('3', '103', 'JavaScript', '2024-03-18', '3')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('3', '104', 'React Basics', '2024-04-22', '2')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('3', '105', 'Node.js', '2024-05-28', '3')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('4', '101', 'Python Basics', '2024-01-12', '5')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('4', '108', 'Data Science', '2024-02-16', '5')",
|
||
"insert into course_completions (user_id, course_id, course_name, completion_date, course_rating) values ('4', '109', 'Machine Learning', '2024-03-22', '5')"
|
||
],
|
||
"enableRunCode": true,
|
||
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\\r\\n\\r\\n<p>\\u6ce8\\u610f\\uff1a\\u56e0\\u4e3a\\u5386\\u53f2\\u539f\\u56e0\\uff0c\\u6211\\u4eec\\u6ca1\\u6709\\u542f\\u7528\\u4efb\\u4f55 SQL \\u6a21\\u5f0f\\uff0c\\u5305\\u62ec <code>ONLY_FULL_GROUP_BY<\\/code>, <code>STRICT_TRANS_TABLES<\\/code>, <code>NO_ZERO_IN_DATE<\\/code>, <code>NO_ZERO_DATE<\\/code>, <code>ERROR_FOR_DIVISION_BY_ZERO<\\/code> \\u7b49\\u3002<\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.2.2 and NumPy 1.26.4<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
|
||
"book": null,
|
||
"isSubscribed": false,
|
||
"isDailyQuestion": false,
|
||
"dailyRecordStatus": null,
|
||
"editorType": "CKEDITOR",
|
||
"ugcQuestionId": null,
|
||
"style": "LEETCODE",
|
||
"exampleTestcases": "{\"headers\":{\"course_completions\":[\"user_id\",\"course_id\",\"course_name\",\"completion_date\",\"course_rating\"]},\"rows\":{\"course_completions\":[[1,101,\"Python Basics\",\"2024-01-05\",5],[1,102,\"SQL Fundamentals\",\"2024-02-10\",4],[1,103,\"JavaScript\",\"2024-03-15\",5],[1,104,\"React Basics\",\"2024-04-20\",4],[1,105,\"Node.js\",\"2024-05-25\",5],[1,106,\"Docker\",\"2024-06-30\",4],[2,101,\"Python Basics\",\"2024-01-08\",4],[2,104,\"React Basics\",\"2024-02-14\",5],[2,105,\"Node.js\",\"2024-03-20\",4],[2,106,\"Docker\",\"2024-04-25\",5],[2,107,\"AWS Fundamentals\",\"2024-05-30\",4],[3,101,\"Python Basics\",\"2024-01-10\",3],[3,102,\"SQL Fundamentals\",\"2024-02-12\",3],[3,103,\"JavaScript\",\"2024-03-18\",3],[3,104,\"React Basics\",\"2024-04-22\",2],[3,105,\"Node.js\",\"2024-05-28\",3],[4,101,\"Python Basics\",\"2024-01-12\",5],[4,108,\"Data Science\",\"2024-02-16\",5],[4,109,\"Machine Learning\",\"2024-03-22\",5]]}}",
|
||
"__typename": "QuestionNode"
|
||
}
|
||
}
|
||
} |