1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/originData/last-person-to-fit-in-the-bus.json

93 lines
11 KiB
JSON
Raw Normal View History

2023-12-09 18:53:53 +08:00
{
"data": {
"question": {
"questionId": "1327",
"questionFrontendId": "1204",
"categoryTitle": "Database",
"boundTopicId": 33152,
"title": "Last Person to Fit in the Bus",
"titleSlug": "last-person-to-fit-in-the-bus",
"content": "<p>Table: <code>Queue</code></p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| person_id | int |\n| person_name | varchar |\n| weight | int |\n| turn | int |\n+-------------+---------+\nperson_id column contains unique values.\nThis table has the information about all people waiting for a bus.\nThe person_id and turn columns will contain all numbers from 1 to n, where n is the number of rows in the table.\nturn determines the order of which the people will board the bus, where turn=1 denotes the first person to board and turn=n denotes the last person to board.\nweight is the weight of the person in kilograms.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>There is a queue of people waiting to board a bus. However, the bus has a weight limit of <code>1000</code><strong> kilograms</strong>, so there may be some people who cannot board.</p>\n\n<p>Write a solution to find the <code>person_name</code> of the <strong>last person</strong> that can fit on the bus without exceeding the weight limit. The test cases are generated such that the first person does not exceed the weight limit.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nQueue table:\n+-----------+-------------+--------+------+\n| person_id | person_name | weight | turn |\n+-----------+-------------+--------+------+\n| 5 | Alice | 250 | 1 |\n| 4 | Bob | 175 | 5 |\n| 3 | Alex | 350 | 2 |\n| 6 | John Cena | 400 | 3 |\n| 1 | Winston | 500 | 6 |\n| 2 | Marie | 200 | 4 |\n+-----------+-------------+--------+------+\n<strong>Output:</strong> \n+-------------+\n| person_name |\n+-------------+\n| John Cena |\n+-------------+\n<strong>Explanation:</strong> The folowing table is ordered by the turn for simplicity.\n+------+----+-----------+--------+--------------+\n| Turn | ID | Name | Weight | Total Weight |\n+------+----+-----------+--------+--------------+\n| 1 | 5 | Alice | 250 | 250 |\n| 2 | 3 | Alex | 350 | 600 |\n| 3 | 6 | John Cena | 400 | 1000 | (last person to board)\n| 4 | 2 | Marie | 200 | 1200 | (cannot board)\n| 5 | 4 | Bob | 175 | ___ |\n| 6 | 1 | Winston | 500 | ___ |\n+------+----+-----------+--------+--------------+\n</pre>\n",
"translatedTitle": "最后一个能进入巴士的人",
"translatedContent": "<p>表: <code>Queue</code></p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| person_id | int |\n| person_name | varchar |\n| weight | int |\n| turn | int |\n+-------------+---------+\nperson_id 是这个表具有唯一值的列。\n该表展示了所有候车乘客的信息。\n表中 person_id 和 turn 列将包含从 1 到 n 的所有数字,其中 n 是表中的行数。\nturn 决定了候车乘客上巴士的顺序,其中 turn=1 表示第一个上巴士turn=n 表示最后一个上巴士。\nweight 表示候车乘客的体重,以千克为单位。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>有一队乘客在等着上巴士。然而,巴士有<code>1000</code>&nbsp; <strong>千克</strong> 的重量限制,所以其中一部分乘客可能无法上巴士。</p>\n\n<p>编写解决方案找出 <strong>最后一个</strong> 上巴士且不超过重量限制的乘客,并报告 <code>person_name</code> 。题目测试用例确保顺位第一的人可以上巴士且不会超重。</p>\n\n<p>返回结果格式如下所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\nQueue 表\n+-----------+-------------+--------+------+\n| person_id | person_name | weight | turn |\n+-----------+-------------+--------+------+\n| 5 | Alice | 250 | 1 |\n| 4 | Bob | 175 | 5 |\n| 3 | Alex | 350 | 2 |\n| 6 | John Cena | 400 | 3 |\n| 1 | Winston | 500 | 6 |\n| 2 | Marie | 200 | 4 |\n+-----------+-------------+--------+------+\n<strong>输出:</strong>\n+-------------+\n| person_name |\n+-------------+\n| John Cena |\n+-------------+\n<strong>解释:</strong>\n为了简化Queue 表按 turn 列由小到大排序。\n+------+----+-----------+--------+--------------+\n| Turn | ID | Name | Weight | Total Weight |\n+------+----+-----------+--------+--------------+\n| 1 | 5 | Alice | 250 | 250 |\n| 2 | 3 | Alex | 350 | 600 |\n| 3 | 6 | John Cena | 400 | 1000 | (最后一个上巴士)\n| 4 | 2 | Marie | 200 | 1200 | (无法上巴士)\n| 5 | 4 | Bob | 175 | ___ |\n| 6 | 1 | Winston | 500 | ___ |\n+------+----+-----------+--------+--------------+</pre>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 102,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": "数据库",
"__typename": "TopicTagNode"
}
],
"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": "Oracle",
"langSlug": "oraclesql",
"code": "/* Write your PL/SQL query statement below */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Pandas",
"langSlug": "pythondata",
"code": "import pandas as pd\n\ndef last_passenger(queue: pd.DataFrame) -> pd.DataFrame:\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "PostgreSQL",
"langSlug": "postgresql",
"code": "-- Write your PostgreSQL query statement below",
"__typename": "CodeSnippetNode"
}
],
2023-12-09 19:57:46 +08:00
"stats": "{\"totalAccepted\": \"20.1K\", \"totalSubmission\": \"28.4K\", \"totalAcceptedRaw\": 20123, \"totalSubmissionRaw\": 28381, \"acRate\": \"70.9%\"}",
2023-12-09 18:53:53 +08:00
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Queue\":[\"person_id\",\"person_name\",\"weight\",\"turn\"]},\"rows\":{\"Queue\":[[5,\"Alice\",250,1],[4,\"Bob\",175,5],[3,\"Alex\",350,2],[6,\"John Cena\",400,3],[1,\"Winston\",500,6],[2,\"Marie\",200,4]]}}",
"metaData": "{\"manual\":false,\"mysql\":[\"Create table If Not Exists Queue (person_id int, person_name varchar(30), weight int, turn int)\"],\"mssql\":[\"Create table Queue (person_id int, person_name varchar(30), weight int, turn int)\"],\"oraclesql\":[\"Create table Queue (person_id int, person_name varchar(30), weight int, turn int)\"],\"database\":true,\"name\":\"last_passenger\",\"pythondata\":[\"Queue = pd.DataFrame([], columns=['person_id', 'person_name', 'weight', 'turn']).astype({'person_id':'Int64', 'person_name':'object', 'weight':'Int64', 'turn':'Int64'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Queue (person_id int, person_name varchar(30), weight int, turn int)\"],\"database_schema\":{\"Queue\":{\"person_id\":\"INT\",\"person_name\":\"VARCHAR(30)\",\"weight\":\"INT\",\"turn\":\"INT\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table If Not Exists Queue (person_id int, person_name varchar(30), weight int, turn int)",
"Truncate table Queue",
"insert into Queue (person_id, person_name, weight, turn) values ('5', 'Alice', '250', '1')",
"insert into Queue (person_id, person_name, weight, turn) values ('4', 'Bob', '175', '5')",
"insert into Queue (person_id, person_name, weight, turn) values ('3', 'Alex', '350', '2')",
"insert into Queue (person_id, person_name, weight, turn) values ('6', 'John Cena', '400', '3')",
"insert into Queue (person_id, person_name, weight, turn) values ('1', 'Winston', '500', '6')",
"insert into Queue (person_id, person_name, weight, turn) values ('2', 'Marie', '200', '4')"
],
"enableRunCode": true,
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/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.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"Queue\":[\"person_id\",\"person_name\",\"weight\",\"turn\"]},\"rows\":{\"Queue\":[[5,\"Alice\",250,1],[4,\"Bob\",175,5],[3,\"Alex\",350,2],[6,\"John Cena\",400,3],[1,\"Winston\",500,6],[2,\"Marie\",200,4]]}}",
"__typename": "QuestionNode"
}
}
}