mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 10:38:13 +08:00
update
This commit is contained in:
parent
b545ef1222
commit
b1fc2c627d
@ -1,6 +1,6 @@
|
||||
# 力扣题库(完整版)
|
||||
|
||||
> 最后更新日期: **2024.06.25**
|
||||
> 最后更新日期: **2024.06.26**
|
||||
>
|
||||
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,58 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3505",
|
||||
"questionFrontendId": "3198",
|
||||
"categoryTitle": "Database",
|
||||
"boundTopicId": 2821350,
|
||||
"title": "Find Cities in Each State",
|
||||
"titleSlug": "find-cities-in-each-state",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"contributors": [],
|
||||
"langToValidPlayground": null,
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"2\", \"totalSubmission\": \"3\", \"totalAcceptedRaw\": 2, \"totalSubmissionRaw\": 3, \"acRate\": \"66.7%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"cities\":[\"state\",\"city\"]},\"rows\":{\"cities\":[[\"California\",\"Los Angeles\"],[\"California\",\"San Francisco\"],[\"California\",\"San Diego\"],[\"Texas\",\"Houston\"],[\"Texas\",\"Austin\"],[\"Texas\",\"Dallas\"],[\"New York\",\"New York City\"],[\"New York\",\"Buffalo\"],[\"New York\",\"Rochester\"]]}}",
|
||||
"metaData": "{\"mysql\":[\"Create table if not exists cities( state varchar(100),city varchar(100))\"],\"mssql\":[\"Create table cities( state varchar(100),city varchar(100))\"],\"oraclesql\":[\"Create table cities( state varchar2(100),city varchar2(100))\"],\"database\":true,\"name\":\"find_cities\",\"postgresql\":[\"CREATE TABLE IF NOT EXISTS cities (\\n state VARCHAR(100),\\n city VARCHAR(100)\\n);\"],\"pythondata\":[\"cities = pd.DataFrame(columns=['state', 'city'])\"],\"database_schema\":{\"cities\":{\"state\":\"VARCHAR(100)\",\"city\":\"VARCHAR(100)\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table if not exists cities( state varchar(100),city varchar(100))",
|
||||
"Truncate table cities",
|
||||
"insert into cities (state, city) values ('California', 'Los Angeles')",
|
||||
"insert into cities (state, city) values ('California', 'San Francisco')",
|
||||
"insert into cities (state, city) values ('California', 'San Diego')",
|
||||
"insert into cities (state, city) values ('Texas', 'Houston')",
|
||||
"insert into cities (state, city) values ('Texas', 'Austin')",
|
||||
"insert into cities (state, city) values ('Texas', 'Dallas')",
|
||||
"insert into cities (state, city) values ('New York', 'New York City')",
|
||||
"insert into cities (state, city) values ('New York', 'Buffalo')",
|
||||
"insert into cities (state, city) values ('New York', 'Rochester')"
|
||||
],
|
||||
"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\":{\"cities\":[\"state\",\"city\"]},\"rows\":{\"cities\":[[\"California\",\"Los Angeles\"],[\"California\",\"San Francisco\"],[\"California\",\"San Diego\"],[\"Texas\",\"Houston\"],[\"Texas\",\"Austin\"],[\"Texas\",\"Dallas\"],[\"New York\",\"New York City\"],[\"New York\",\"Buffalo\"],[\"New York\",\"Rochester\"]]}}",
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -0,0 +1,59 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3473",
|
||||
"questionFrontendId": "3166",
|
||||
"boundTopicId": null,
|
||||
"title": "Calculate Parking Fees and Duration",
|
||||
"titleSlug": "calculate-parking-fees-and-duration",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 4,
|
||||
"dislikes": 1,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "{\"headers\":{\"ParkingTransactions\":[\"lot_id\",\"car_id\",\"entry_time\",\"exit_time\",\"fee_paid\"]},\"rows\":{\"ParkingTransactions\":[[1,1001,\"2023-06-01 08:00:00\",\"2023-06-01 10:30:00\",5.00],[1,1001,\"2023-06-02 11:00:00\",\"2023-06-02 12:45:00\",3.00],[2,1001,\"2023-06-01 10:45:00\",\"2023-06-01 12:00:00\",6.00],[2,1002,\"2023-06-01 09:00:00\",\"2023-06-01 11:30:00\",4.00],[3,1001,\"2023-06-03 07:00:00\",\"2023-06-03 09:00:00\",4.00],[3,1002,\"2023-06-02 12:00:00\",\"2023-06-02 14:00:00\",2.00]]}}",
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": null,
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"377\", \"totalSubmission\": \"631\", \"totalAcceptedRaw\": 377, \"totalSubmissionRaw\": 631, \"acRate\": \"59.7%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"ParkingTransactions\":[\"lot_id\",\"car_id\",\"entry_time\",\"exit_time\",\"fee_paid\"]},\"rows\":{\"ParkingTransactions\":[[1,1001,\"2023-06-01 08:00:00\",\"2023-06-01 10:30:00\",5.00],[1,1001,\"2023-06-02 11:00:00\",\"2023-06-02 12:45:00\",3.00],[2,1001,\"2023-06-01 10:45:00\",\"2023-06-01 12:00:00\",6.00],[2,1002,\"2023-06-01 09:00:00\",\"2023-06-01 11:30:00\",4.00],[3,1001,\"2023-06-03 07:00:00\",\"2023-06-03 09:00:00\",4.00],[3,1002,\"2023-06-02 12:00:00\",\"2023-06-02 14:00:00\",2.00]]}}",
|
||||
"metaData": "{\"mysql\": [\"CREATE TABLE If not exists ParkingTransactions (\\n lot_id INT,\\n car_id INT,\\n entry_time DATETIME,\\n exit_time DATETIME,\\n fee_paid DECIMAL(10, 2)\\n)\\n\"], \"mssql\": [\"CREATE TABLE ParkingTransactions (\\n lot_id INT,\\n car_id INT,\\n entry_time DATETIME,\\n exit_time DATETIME,\\n fee_paid DECIMAL(10, 2)\\n);\\n\"], \"oraclesql\": [\"CREATE TABLE ParkingTransactions (\\n lot_id NUMBER,\\n car_id NUMBER,\\n entry_time DATE,\\n exit_time DATE,\\n fee_paid NUMBER(10, 2)\\n)\\n\", \"ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS'\"], \"database\": true, \"name\": \"calculate_fees_and_duration\", \"postgresql\": [\"CREATE TABLE IF NOT EXISTS ParkingTransactions (\\n lot_id INTEGER,\\n car_id INTEGER,\\n entry_time TIMESTAMP,\\n exit_time TIMESTAMP,\\n fee_paid NUMERIC(10, 2)\\n);\"], \"pythondata\": [\"ParkingTransactions = pd.DataFrame([], columns=['lot_id', 'car_id', 'entry_time', 'exit_time', 'fee_paid']).astype({\\n 'lot_id': 'Int64',\\n 'car_id': 'Int64',\\n 'entry_time': 'datetime64[ns]',\\n 'exit_time': 'datetime64[ns]',\\n 'fee_paid': 'float64'\\n})\"], \"database_schema\": {\"ParkingTransactions\": {\"lot_id\": \"INT\", \"car_id\": \"INT\", \"entry_time\": \"DATETIME\", \"exit_time\": \"DATETIME\", \"fee_paid\": \"DECIMAL(10, 2)\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"CREATE TABLE If not exists ParkingTransactions (\n lot_id INT,\n car_id INT,\n entry_time DATETIME,\n exit_time DATETIME,\n fee_paid DECIMAL(10, 2)\n)\n",
|
||||
"Truncate table ParkingTransactions",
|
||||
"insert into ParkingTransactions (lot_id, car_id, entry_time, exit_time, fee_paid) values ('1', '1001', '2023-06-01 08:00:00', '2023-06-01 10:30:00', '5.0')",
|
||||
"insert into ParkingTransactions (lot_id, car_id, entry_time, exit_time, fee_paid) values ('1', '1001', '2023-06-02 11:00:00', '2023-06-02 12:45:00', '3.0')",
|
||||
"insert into ParkingTransactions (lot_id, car_id, entry_time, exit_time, fee_paid) values ('2', '1001', '2023-06-01 10:45:00', '2023-06-01 12:00:00', '6.0')",
|
||||
"insert into ParkingTransactions (lot_id, car_id, entry_time, exit_time, fee_paid) values ('2', '1002', '2023-06-01 09:00:00', '2023-06-01 11:30:00', '4.0')",
|
||||
"insert into ParkingTransactions (lot_id, car_id, entry_time, exit_time, fee_paid) values ('3', '1001', '2023-06-03 07:00:00', '2023-06-03 09:00:00', '4.0')",
|
||||
"insert into ParkingTransactions (lot_id, car_id, entry_time, exit_time, fee_paid) values ('3', '1002', '2023-06-02 12:00:00', '2023-06-02 14:00:00', '2.0')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"], \"pythondata\": [\"Pandas\", \"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0</p>\"], \"postgresql\": [\"PostgreSQL\", \"<p>PostgreSQL 16</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3448",
|
||||
"questionFrontendId": "3140",
|
||||
"boundTopicId": null,
|
||||
"title": "Consecutive Available Seats II",
|
||||
"titleSlug": "consecutive-available-seats-ii",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 2,
|
||||
"dislikes": 2,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "{\"headers\":{\"Cinema\":[\"seat_id\",\"free\"]},\"rows\":{\"Cinema\":[[1,1],[2,0],[3,1],[4,1],[5,1]]}}",
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": null,
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"513\", \"totalSubmission\": \"807\", \"totalAcceptedRaw\": 513, \"totalSubmissionRaw\": 807, \"acRate\": \"63.6%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"Cinema\":[\"seat_id\",\"free\"]},\"rows\":{\"Cinema\":[[1,1],[2,0],[3,1],[4,1],[5,1]]}}",
|
||||
"metaData": "{\"mysql\": [\"CREATE TABLE if Not exists Cinema (\\n seat_id INT PRIMARY KEY AUTO_INCREMENT,\\n free BOOLEAN\\n)\\n\"], \"mssql\": [\"Create table Cinema (seat_id int primary key, free BIT)\\n\"], \"oraclesql\": [\"CREATE TABLE Cinema (\\n seat_id INT PRIMARY KEY,\\n free NUMBER(1,0)\\n)\\n\"], \"database\": true, \"name\": \"consecutive_available_seats\", \"postgresql\": [\"CREATE TABLE Cinema (\\n seat_id INT PRIMARY KEY,\\n free INT CHECK (free IN (0, 1))\\n);\"], \"pythondata\": [\"Cinema = pd.DataFrame({'seat_id': pd.Series(dtype='int'), 'free': pd.Series(dtype='bool')})\"], \"database_schema\": {\"Cinema\": {\"seat_id\": \"INT\", \"free\": \"BOOLEAN\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"CREATE TABLE if Not exists Cinema (\n seat_id INT PRIMARY KEY AUTO_INCREMENT,\n free BOOLEAN\n)\n",
|
||||
"Truncate table Cinema",
|
||||
"insert into Cinema (seat_id, free) values ('1', '1')",
|
||||
"insert into Cinema (seat_id, free) values ('2', '0')",
|
||||
"insert into Cinema (seat_id, free) values ('3', '1')",
|
||||
"insert into Cinema (seat_id, free) values ('4', '1')",
|
||||
"insert into Cinema (seat_id, free) values ('5', '1')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"], \"pythondata\": [\"Pandas\", \"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0</p>\"], \"postgresql\": [\"PostgreSQL\", \"<p>PostgreSQL 16</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3505",
|
||||
"questionFrontendId": "3198",
|
||||
"boundTopicId": null,
|
||||
"title": "Find Cities in Each State",
|
||||
"titleSlug": "find-cities-in-each-state",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 0,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "{\"headers\":{\"cities\":[\"state\",\"city\"]},\"rows\":{\"cities\":[[\"California\",\"Los Angeles\"],[\"California\",\"San Francisco\"],[\"California\",\"San Diego\"],[\"Texas\",\"Houston\"],[\"Texas\",\"Austin\"],[\"Texas\",\"Dallas\"],[\"New York\",\"New York City\"],[\"New York\",\"Buffalo\"],[\"New York\",\"Rochester\"]]}}",
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"58\", \"totalSubmission\": \"58\", \"totalAcceptedRaw\": 58, \"totalSubmissionRaw\": 58, \"acRate\": \"100.0%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"cities\":[\"state\",\"city\"]},\"rows\":{\"cities\":[[\"California\",\"Los Angeles\"],[\"California\",\"San Francisco\"],[\"California\",\"San Diego\"],[\"Texas\",\"Houston\"],[\"Texas\",\"Austin\"],[\"Texas\",\"Dallas\"],[\"New York\",\"New York City\"],[\"New York\",\"Buffalo\"],[\"New York\",\"Rochester\"]]}}",
|
||||
"metaData": "{\"mysql\": [\"Create table if not exists cities( state varchar(100),city varchar(100))\"], \"mssql\": [\"Create table cities( state varchar(100),city varchar(100))\"], \"oraclesql\": [\"Create table cities( state varchar2(100),city varchar2(100))\"], \"database\": true, \"name\": \"find_cities\", \"postgresql\": [\"CREATE TABLE IF NOT EXISTS cities (\\n state VARCHAR(100),\\n city VARCHAR(100)\\n);\"], \"pythondata\": [\"cities = pd.DataFrame(columns=['state', 'city'])\"], \"database_schema\": {\"cities\": {\"state\": \"VARCHAR(100)\", \"city\": \"VARCHAR(100)\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table if not exists cities( state varchar(100),city varchar(100))",
|
||||
"Truncate table cities",
|
||||
"insert into cities (state, city) values ('California', 'Los Angeles')",
|
||||
"insert into cities (state, city) values ('California', 'San Francisco')",
|
||||
"insert into cities (state, city) values ('California', 'San Diego')",
|
||||
"insert into cities (state, city) values ('Texas', 'Houston')",
|
||||
"insert into cities (state, city) values ('Texas', 'Austin')",
|
||||
"insert into cities (state, city) values ('Texas', 'Dallas')",
|
||||
"insert into cities (state, city) values ('New York', 'New York City')",
|
||||
"insert into cities (state, city) values ('New York', 'Buffalo')",
|
||||
"insert into cities (state, city) values ('New York', 'Rochester')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"], \"pythondata\": [\"Pandas\", \"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0</p>\"], \"postgresql\": [\"PostgreSQL\", \"<p>PostgreSQL 16</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,81 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3503",
|
||||
"questionFrontendId": "3188",
|
||||
"boundTopicId": null,
|
||||
"title": "Find Top Scoring Students II",
|
||||
"titleSlug": "find-top-scoring-students-ii",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Hard",
|
||||
"likes": 4,
|
||||
"dislikes": 2,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "{\"headers\":{\"students\":[\"student_id\",\"name\",\"major\"],\"courses\":[\"course_id\",\"name\",\"credits\",\"major\",\"mandatory\"],\"enrollments\":[\"student_id\",\"course_id\",\"semester\",\"grade\",\"GPA\"]},\"rows\":{\"students\":[[1,\"Alice\",\"Computer Science\"],[2,\"Bob\",\"Computer Science\"],[3,\"Charlie\",\"Mathematics\"],[4,\"David\",\"Mathematics\"]],\"courses\":[[101,\"Algorithms\",3,\"Computer Science\",\"Yes\"],[102,\"Data Structures\",3,\"Computer Science\",\"Yes\"],[103,\"Calculus\",4,\"Mathematics\",\"Yes\"],[104,\"Linear Algebra\",4,\"Mathematics\",\"Yes\"],[105,\"Machine Learning\",3,\"Computer Science\",\"No\"],[106,\"Probability\",3,\"Mathematics\",\"No\"],[107,\"Operating Systems\",3,\"Computer Science\",\"No\"],[108,\"Statistics\",3,\"Mathematics\",\"No\"]],\"enrollments\":[[1,101,\"Fall 2023\",\"A\",4.0],[1,102,\"Spring 2023\",\"A\",4.0],[1,105,\"Spring 2023\",\"A\",4.0],[1,107,\"Fall 2023\",\"B\",3.5],[2,101,\"Fall 2023\",\"A\",4.0],[2,102,\"Spring 2023\",\"B\",3.0],[3,103,\"Fall 2023\",\"A\",4.0],[3,104,\"Spring 2023\",\"A\",4.0],[3,106,\"Spring 2023\",\"A\",4.0],[3,108,\"Fall 2023\",\"B\",3.5],[4,103,\"Fall 2023\",\"B\",3.0],[4,104,\"Spring 2023\",\"B\",3.0]]}}",
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": null,
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"180\", \"totalSubmission\": \"327\", \"totalAcceptedRaw\": 180, \"totalSubmissionRaw\": 327, \"acRate\": \"55.0%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"students\":[\"student_id\",\"name\",\"major\"],\"courses\":[\"course_id\",\"name\",\"credits\",\"major\",\"mandatory\"],\"enrollments\":[\"student_id\",\"course_id\",\"semester\",\"grade\",\"GPA\"]},\"rows\":{\"students\":[[1,\"Alice\",\"Computer Science\"],[2,\"Bob\",\"Computer Science\"],[3,\"Charlie\",\"Mathematics\"],[4,\"David\",\"Mathematics\"]],\"courses\":[[101,\"Algorithms\",3,\"Computer Science\",\"Yes\"],[102,\"Data Structures\",3,\"Computer Science\",\"Yes\"],[103,\"Calculus\",4,\"Mathematics\",\"Yes\"],[104,\"Linear Algebra\",4,\"Mathematics\",\"Yes\"],[105,\"Machine Learning\",3,\"Computer Science\",\"No\"],[106,\"Probability\",3,\"Mathematics\",\"No\"],[107,\"Operating Systems\",3,\"Computer Science\",\"No\"],[108,\"Statistics\",3,\"Mathematics\",\"No\"]],\"enrollments\":[[1,101,\"Fall 2023\",\"A\",4.0],[1,102,\"Spring 2023\",\"A\",4.0],[1,105,\"Spring 2023\",\"A\",4.0],[1,107,\"Fall 2023\",\"B\",3.5],[2,101,\"Fall 2023\",\"A\",4.0],[2,102,\"Spring 2023\",\"B\",3.0],[3,103,\"Fall 2023\",\"A\",4.0],[3,104,\"Spring 2023\",\"A\",4.0],[3,106,\"Spring 2023\",\"A\",4.0],[3,108,\"Fall 2023\",\"B\",3.5],[4,103,\"Fall 2023\",\"B\",3.0],[4,104,\"Spring 2023\",\"B\",3.0]]}}",
|
||||
"metaData": "{\"mysql\": [\"CREATE TABLE if not exists students (\\n student_id INT ,\\n name VARCHAR(255),\\n major VARCHAR(255)\\n)\", \"CREATE TABLE if not exists courses (\\n course_id INT ,\\n name VARCHAR(255),\\n credits INT,\\n major VARCHAR(255),\\n mandatory ENUM('yes', 'no') DEFAULT 'no'\\n)\", \"CREATE TABLE if not exists enrollments (\\n student_id INT,\\n course_id INT,\\n semester VARCHAR(255),\\n grade VARCHAR(10),\\nGPA decimal(3,2)\\n\\n);\"], \"mssql\": [\"CREATE TABLE students (\\n student_id INT ,\\n name VARCHAR(255),\\n major VARCHAR(255)\\n)\", \"CREATE TABLE courses (\\n course_id INT PRIMARY KEY,\\n name VARCHAR(255),\\n credits INT,\\n major VARCHAR(255),\\n mandatory VARCHAR(3) CHECK (mandatory IN ('yes', 'no')) DEFAULT 'no'\\n)\", \"CREATE TABLE enrollments (\\n student_id INT,\\n course_id INT,\\n semester VARCHAR(255),\\n grade VARCHAR(1),\\n GPA DECIMAL(3,2)\\n)\"], \"oraclesql\": [\"CREATE TABLE students (\\n student_id NUMBER ,\\n name VARCHAR2(255),\\n major VARCHAR2(255)\\n)\", \"CREATE TABLE courses (\\n course_id NUMBER ,\\n name VARCHAR2(255),\\n credits NUMBER,\\n major VARCHAR2(255),\\n mandatory VARCHAR2(3) CHECK (mandatory IN ('Yes', 'No')) \\n)\", \"CREATE TABLE enrollments (\\n student_id NUMBER,\\n course_id NUMBER,\\n semester VARCHAR2(255),\\n grade VARCHAR2(1),\\n GPA Number (3,2)\\n)\"], \"database\": true, \"name\": \"find_top_scoring_students\", \"pythondata\": [\"students = pd.DataFrame([], columns=['student_id', 'name', 'major']).astype({\\n 'student_id': 'Int64', # Nullable integer type for student_id\\n 'name': 'string', # String type for names\\n 'major': 'string' # String type for majors\\n})\", \"courses = pd.DataFrame([], columns=['course_id', 'name', 'credits', 'major', 'mandatory']).astype({'course_id': 'Int64', 'name': 'string', 'credits': 'Int64', 'major': 'string', 'mandatory': 'string'})\\n\\n # pd.CategoricalDtype(categories=['yes', 'no'])\\n\", \"enrollments = pd.DataFrame([], columns=['student_id', 'course_id', 'semester', 'grade', 'GPA']).astype({'student_id': 'Int64', 'course_id': 'Int64', 'semester': 'string', 'grade': 'string', 'GPA': 'float'})\\n\"], \"postgresql\": [\"CREATE TABLE IF NOT EXISTS students (\\n student_id SERIAL,\\n name VARCHAR(255),\\n major VARCHAR(255)\\n);\", \"CREATE TABLE courses (\\n course_id INTEGER, -- or SERIAL if you want auto-increment\\n name VARCHAR(255),\\n credits INTEGER, -- or NUMERIC if you need decimal places\\n major VARCHAR(255),\\n mandatory VARCHAR(3) CHECK (mandatory IN ('Yes', 'No'))\\n);\\n\", \"CREATE TABLE IF NOT EXISTS enrollments (\\n student_id INT,\\n course_id INT,\\n semester VARCHAR(255),\\n grade VARCHAR(10),\\n GPA NUMERIC(3,2)\\n);\\n\"], \"database_schema\": {\"students\": {\"student_id\": \"INT\", \"name\": \"VARCHAR(255)\", \"major\": \"VARCHAR(255)\"}, \"courses\": {\"course_id\": \"INT\", \"name\": \"VARCHAR(255)\", \"credits\": \"INT\", \"major\": \"VARCHAR(255)\", \"mandatory\": \"ENUM('yes', 'no')\"}, \"enrollments\": {\"student_id\": \"INT\", \"course_id\": \"INT\", \"semester\": \"VARCHAR(255)\", \"grade\": \"VARCHAR(10)\", \"GPA\": \"DECIMAL(3, 2)\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"CREATE TABLE if not exists students (\n student_id INT ,\n name VARCHAR(255),\n major VARCHAR(255)\n)",
|
||||
"CREATE TABLE if not exists courses (\n course_id INT ,\n name VARCHAR(255),\n credits INT,\n major VARCHAR(255),\n mandatory ENUM('yes', 'no') DEFAULT 'no'\n)",
|
||||
"CREATE TABLE if not exists enrollments (\n student_id INT,\n course_id INT,\n semester VARCHAR(255),\n grade VARCHAR(10),\nGPA decimal(3,2)\n\n);",
|
||||
"Truncate table students",
|
||||
"insert into students (student_id, name, major) values ('1', 'Alice', 'Computer Science')",
|
||||
"insert into students (student_id, name, major) values ('2', 'Bob', 'Computer Science')",
|
||||
"insert into students (student_id, name, major) values ('3', 'Charlie', 'Mathematics')",
|
||||
"insert into students (student_id, name, major) values ('4', 'David', 'Mathematics')",
|
||||
"Truncate table courses",
|
||||
"insert into courses (course_id, name, credits, major, mandatory) values ('101', 'Algorithms', '3', 'Computer Science', 'Yes')",
|
||||
"insert into courses (course_id, name, credits, major, mandatory) values ('102', 'Data Structures', '3', 'Computer Science', 'Yes')",
|
||||
"insert into courses (course_id, name, credits, major, mandatory) values ('103', 'Calculus', '4', 'Mathematics', 'Yes')",
|
||||
"insert into courses (course_id, name, credits, major, mandatory) values ('104', 'Linear Algebra', '4', 'Mathematics', 'Yes')",
|
||||
"insert into courses (course_id, name, credits, major, mandatory) values ('105', 'Machine Learning', '3', 'Computer Science', 'No')",
|
||||
"insert into courses (course_id, name, credits, major, mandatory) values ('106', 'Probability', '3', 'Mathematics', 'No')",
|
||||
"insert into courses (course_id, name, credits, major, mandatory) values ('107', 'Operating Systems', '3', 'Computer Science', 'No')",
|
||||
"insert into courses (course_id, name, credits, major, mandatory) values ('108', 'Statistics', '3', 'Mathematics', 'No')",
|
||||
"Truncate table enrollments",
|
||||
"insert into enrollments (student_id, course_id, semester, grade, GPA) values ('1', '101', 'Fall 2023', 'A', '4.0')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade, GPA) values ('1', '102', 'Spring 2023', 'A', '4.0')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade, GPA) values ('1', '105', 'Spring 2023', 'A', '4.0')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade, GPA) values ('1', '107', 'Fall 2023', 'B', '3.5')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade, GPA) values ('2', '101', 'Fall 2023', 'A', '4.0')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade, GPA) values ('2', '102', 'Spring 2023', 'B', '3.0')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade, GPA) values ('3', '103', 'Fall 2023', 'A', '4.0')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade, GPA) values ('3', '104', 'Spring 2023', 'A', '4.0')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade, GPA) values ('3', '106', 'Spring 2023', 'A', '4.0')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade, GPA) values ('3', '108', 'Fall 2023', 'B', '3.5')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade, GPA) values ('4', '103', 'Fall 2023', 'B', '3.0')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade, GPA) values ('4', '104', 'Spring 2023', 'B', '3.0')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"], \"pythondata\": [\"Pandas\", \"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0</p>\"], \"postgresql\": [\"PostgreSQL\", \"<p>PostgreSQL 16</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3488",
|
||||
"questionFrontendId": "3182",
|
||||
"boundTopicId": null,
|
||||
"title": "Find Top Scoring Students",
|
||||
"titleSlug": "find-top-scoring-students",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Medium",
|
||||
"likes": 4,
|
||||
"dislikes": 2,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "{\"headers\":{\"students\":[\"student_id\",\"name\",\"major\"],\"courses\":[\"course_id\",\"name\",\"credits\",\"major\"],\"enrollments\":[\"student_id\",\"course_id\",\"semester\",\"grade\"]},\"rows\":{\"students\":[[1,\"Alice\",\"Computer Science\"],[2,\"Bob\",\"Computer Science\"],[3,\"Charlie\",\"Mathematics\"],[4,\"David\",\"Mathematics\"]],\"courses\":[[101,\"Algorithms\",3,\"Computer Science\"],[102,\"Data Structures\",3,\"Computer Science\"],[103,\"Calculus\",4,\"Mathematics\"],[104,\"Linear Algebra\",4,\"Mathematics\"]],\"enrollments\":[[1,101,\"Fall 2023\",\"A\"],[1,102,\"Fall 2023\",\"A\"],[2,101,\"Fall 2023\",\"B\"],[2,102,\"Fall 2023\",\"A\"],[3,103,\"Fall 2023\",\"A\"],[3,104,\"Fall 2023\",\"A\"],[4,103,\"Fall 2023\",\"A\"],[4,104,\"Fall 2023\",\"B\"]]}}",
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": null,
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"298\", \"totalSubmission\": \"531\", \"totalAcceptedRaw\": 298, \"totalSubmissionRaw\": 531, \"acRate\": \"56.1%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\":{\"students\":[\"student_id\",\"name\",\"major\"],\"courses\":[\"course_id\",\"name\",\"credits\",\"major\"],\"enrollments\":[\"student_id\",\"course_id\",\"semester\",\"grade\"]},\"rows\":{\"students\":[[1,\"Alice\",\"Computer Science\"],[2,\"Bob\",\"Computer Science\"],[3,\"Charlie\",\"Mathematics\"],[4,\"David\",\"Mathematics\"]],\"courses\":[[101,\"Algorithms\",3,\"Computer Science\"],[102,\"Data Structures\",3,\"Computer Science\"],[103,\"Calculus\",4,\"Mathematics\"],[104,\"Linear Algebra\",4,\"Mathematics\"]],\"enrollments\":[[1,101,\"Fall 2023\",\"A\"],[1,102,\"Fall 2023\",\"A\"],[2,101,\"Fall 2023\",\"B\"],[2,102,\"Fall 2023\",\"A\"],[3,103,\"Fall 2023\",\"A\"],[3,104,\"Fall 2023\",\"A\"],[4,103,\"Fall 2023\",\"A\"],[4,104,\"Fall 2023\",\"B\"]]}}",
|
||||
"metaData": "{\"mysql\": [\"CREATE TABLE if not exists students (\\n student_id INT ,\\n name VARCHAR(255),\\n major VARCHAR(255)\\n)\", \"CREATE TABLE if not exists courses (\\n course_id INT ,\\n name VARCHAR(255),\\n credits INT,\\n major VARCHAR(255)\\n)\\n\", \"CREATE TABLE if not exists enrollments (\\n student_id INT,\\n course_id INT,\\n semester VARCHAR(255),\\n grade VARCHAR(10)\\n\\n);\"], \"mssql\": [\"CREATE TABLE students (\\n student_id INT ,\\n name VARCHAR(255),\\n major VARCHAR(255)\\n)\", \"CREATE TABLE courses (\\n course_id INT ,\\n name VARCHAR(255),\\n credits INT,\\n major VARCHAR(255)\\n)\\n\", \"CREATE TABLE enrollments (\\n student_id INT,\\n course_id INT,\\n semester VARCHAR(255),\\n grade VARCHAR(10)\\n\\n);\"], \"oraclesql\": [\"CREATE TABLE students (\\n student_id NUMBER ,\\n name VARCHAR2(255),\\n major VARCHAR2(255)\\n)\", \"CREATE TABLE courses (\\n course_id NUMBER,\\n name VARCHAR2(255),\\n credits NUMBER,\\n major VARCHAR2(255)\\n)\", \"CREATE TABLE enrollments (\\n student_id NUMBER,\\n course_id NUMBER,\\n semester VARCHAR2(255),\\n grade VARCHAR2(10) \\n \\n)\"], \"database\": true, \"name\": \"find_top_scoring_students\", \"pythondata\": [\"enrollments = pd.DataFrame([], columns=['student_id', 'course_id', 'semester', 'grade']).astype({\\n 'student_id': 'Int64', # Nullable integer type\\n 'course_id': 'Int64', # Nullable integer type\\n 'semester': 'object', # Object type for arbitrary strings\\n 'grade': 'object' # Object type for arbitrary strings\\n})\", \"students = pd.DataFrame([], columns=['student_id', 'name', 'major']).astype({\\n 'student_id': 'Int64', # Nullable integer type\\n 'name': 'object', # Object type for arbitrary strings, equivalent to VARCHAR\\n 'major': 'object' # Object type for arbitrary strings, equivalent to VARCHAR\\n})\", \"courses = pd.DataFrame([], columns=['course_id', 'name', 'credits', 'major']).astype({\\n 'course_id': 'Int64', # Nullable integer type\\n 'name': 'object', # Object type for arbitrary strings, equivalent to VARCHAR\\n 'credits': 'Int64', # Nullable integer type\\n 'major': 'object' # Object type for arbitrary strings, equivalent to VARCHAR\\n})\"], \"postgresql\": [\"CREATE TABLE IF NOT EXISTS students (\\n student_id INT,\\n name VARCHAR(255),\\n major VARCHAR(255)\\n);\\n\", \"CREATE TABLE IF NOT EXISTS courses (\\n course_id INT,\\n name VARCHAR(255),\\n credits INT,\\n major VARCHAR(255)\\n);\\n\", \"CREATE TABLE IF NOT EXISTS enrollments (\\n student_id INT,\\n course_id INT,\\n semester VARCHAR(255),\\n grade VARCHAR(10)\\n);\\n\"], \"database_schema\": {\"students\": {\"student_id\": \"INT\", \"name\": \"VARCHAR(255)\", \"major\": \"VARCHAR(255)\"}, \"courses\": {\"course_id\": \"INT\", \"name\": \"VARCHAR(255)\", \"credits\": \"INT\", \"major\": \"VARCHAR(255)\"}, \"enrollments\": {\"student_id\": \"INT\", \"course_id\": \"INT\", \"semester\": \"VARCHAR(255)\", \"grade\": \"VARCHAR(10)\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"CREATE TABLE if not exists students (\n student_id INT ,\n name VARCHAR(255),\n major VARCHAR(255)\n)",
|
||||
"CREATE TABLE if not exists courses (\n course_id INT ,\n name VARCHAR(255),\n credits INT,\n major VARCHAR(255)\n)\n",
|
||||
"CREATE TABLE if not exists enrollments (\n student_id INT,\n course_id INT,\n semester VARCHAR(255),\n grade VARCHAR(10)\n\n);",
|
||||
"Truncate table students",
|
||||
"insert into students (student_id, name, major) values ('1', 'Alice', 'Computer Science')",
|
||||
"insert into students (student_id, name, major) values ('2', 'Bob', 'Computer Science')",
|
||||
"insert into students (student_id, name, major) values ('3', 'Charlie', 'Mathematics')",
|
||||
"insert into students (student_id, name, major) values ('4', 'David', 'Mathematics')",
|
||||
"Truncate table courses",
|
||||
"insert into courses (course_id, name, credits, major) values ('101', 'Algorithms', '3', 'Computer Science')",
|
||||
"insert into courses (course_id, name, credits, major) values ('102', 'Data Structures', '3', 'Computer Science')",
|
||||
"insert into courses (course_id, name, credits, major) values ('103', 'Calculus', '4', 'Mathematics')",
|
||||
"insert into courses (course_id, name, credits, major) values ('104', 'Linear Algebra', '4', 'Mathematics')",
|
||||
"Truncate table enrollments",
|
||||
"insert into enrollments (student_id, course_id, semester, grade) values ('1', '101', 'Fall 2023', 'A')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade) values ('1', '102', 'Fall 2023', 'A')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade) values ('2', '101', 'Fall 2023', 'B')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade) values ('2', '102', 'Fall 2023', 'A')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade) values ('3', '103', 'Fall 2023', 'A')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade) values ('3', '104', 'Fall 2023', 'A')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade) values ('4', '103', 'Fall 2023', 'A')",
|
||||
"insert into enrollments (student_id, course_id, semester, grade) values ('4', '104', 'Fall 2023', 'B')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"], \"pythondata\": [\"Pandas\", \"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0</p>\"], \"postgresql\": [\"PostgreSQL\", \"<p>PostgreSQL 16</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
69
leetcode/originData/[no content]invalid-tweets-ii.json
Normal file
69
leetcode/originData/[no content]invalid-tweets-ii.json
Normal file
@ -0,0 +1,69 @@
|
||||
{
|
||||
"data": {
|
||||
"question": {
|
||||
"questionId": "3457",
|
||||
"questionFrontendId": "3150",
|
||||
"boundTopicId": null,
|
||||
"title": "Invalid Tweets II",
|
||||
"titleSlug": "invalid-tweets-ii",
|
||||
"content": null,
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": true,
|
||||
"difficulty": "Easy",
|
||||
"likes": 4,
|
||||
"dislikes": 1,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
"exampleTestcases": "{\"headers\": {\"Tweets\": [\"tweet_id\", \"content\"]}, \"rows\": {\"Tweets\": [[1, \"What an amazing meal @MaxPower @AlexJones @JohnDoe #Learning #Fitness #Love\"], [2, \"Learning something new every day @AnnaWilson #Learning #Foodie\"], [3, \"Never been happier about today's achievements @SaraJohnson @JohnDoe @AnnaWilson #Fashion\"], [4, \"Traveling, exploring, and living my best life @JaneSmith @JohnDoe @ChrisAnderson @AlexJones #WorkLife #Travel\"], [5, \"Work hard, play hard, and cherish every moment @AlexJones #Fashion #Foodie\"], [6, \"Never been happier about today's achievements @ChrisAnderson #Fashion #WorkLife\"], [7, \"So grateful for today's experiences @AnnaWilson @LisaTaylor @ChrisAnderson @MikeBrown #Fashion #HappyDay #WorkLife #Nature\"], [8, \"What an amazing meal @EmilyClark @AlexJones @MikeBrown #Fitness\"], [9, \"Learning something new every day @EmilyClark @AnnaWilson @MaxPower #Travel\"], [10, \"So grateful for today's experiences @ChrisAnderson #Nature\"], [11, \"So grateful for today's experiences @AlexJones #Art #WorkLife\"], [12, \"Learning something new every day @JaneSmith @MikeBrown #Travel\"], [13, \"What an amazing meal @EmilyClark @JohnDoe @LisaTaylor @MaxPower #Foodie #Fitness\"], [14, \"Work hard, play hard, and cherish every moment @LisaTaylor @SaraJohnson @MaxPower @ChrisAnderson #TechLife #Nature #Music\"], [15, \"What a beautiful day it is @EmilyClark @MaxPower @SaraJohnson #Fashion\"], [16, \"What a beautiful day it is @AnnaWilson @JaneSmith #Fashion #Love #TechLife\"]]}}",
|
||||
"categoryTitle": "Database",
|
||||
"contributors": [],
|
||||
"topicTags": [
|
||||
{
|
||||
"name": "Database",
|
||||
"slug": "database",
|
||||
"translatedName": null,
|
||||
"__typename": "TopicTagNode"
|
||||
}
|
||||
],
|
||||
"companyTagStats": null,
|
||||
"codeSnippets": null,
|
||||
"stats": "{\"totalAccepted\": \"734\", \"totalSubmission\": \"800\", \"totalAcceptedRaw\": 734, \"totalSubmissionRaw\": 800, \"acRate\": \"91.8%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
"sampleTestCase": "{\"headers\": {\"Tweets\": [\"tweet_id\", \"content\"]}, \"rows\": {\"Tweets\": [[1, \"What an amazing meal @MaxPower @AlexJones @JohnDoe #Learning #Fitness #Love\"], [2, \"Learning something new every day @AnnaWilson #Learning #Foodie\"], [3, \"Never been happier about today's achievements @SaraJohnson @JohnDoe @AnnaWilson #Fashion\"], [4, \"Traveling, exploring, and living my best life @JaneSmith @JohnDoe @ChrisAnderson @AlexJones #WorkLife #Travel\"], [5, \"Work hard, play hard, and cherish every moment @AlexJones #Fashion #Foodie\"], [6, \"Never been happier about today's achievements @ChrisAnderson #Fashion #WorkLife\"], [7, \"So grateful for today's experiences @AnnaWilson @LisaTaylor @ChrisAnderson @MikeBrown #Fashion #HappyDay #WorkLife #Nature\"], [8, \"What an amazing meal @EmilyClark @AlexJones @MikeBrown #Fitness\"], [9, \"Learning something new every day @EmilyClark @AnnaWilson @MaxPower #Travel\"], [10, \"So grateful for today's experiences @ChrisAnderson #Nature\"], [11, \"So grateful for today's experiences @AlexJones #Art #WorkLife\"], [12, \"Learning something new every day @JaneSmith @MikeBrown #Travel\"], [13, \"What an amazing meal @EmilyClark @JohnDoe @LisaTaylor @MaxPower #Foodie #Fitness\"], [14, \"Work hard, play hard, and cherish every moment @LisaTaylor @SaraJohnson @MaxPower @ChrisAnderson #TechLife #Nature #Music\"], [15, \"What a beautiful day it is @EmilyClark @MaxPower @SaraJohnson #Fashion\"], [16, \"What a beautiful day it is @AnnaWilson @JaneSmith #Fashion #Love #TechLife\"]]}}",
|
||||
"metaData": "{\"mysql\": [\"Create table If Not Exists Tweets(tweet_id int, content varchar(500))\"], \"mssql\": [\"Create table Tweets(tweet_id int, content varchar(500))\"], \"oraclesql\": [\"Create table Tweets(tweet_id int, content varchar(500))\"], \"database\": true, \"name\": \"find_invalid_tweets\", \"pythondata\": [\"Tweets = pd.DataFrame([], columns=['tweet_id', 'content']).astype({'tweet_id':'Int64', 'content':'object'})\"], \"postgresql\": [\"Create table If Not Exists Tweets(tweet_id int, content varchar(500))\"], \"database_schema\": {\"Tweets\": {\"tweet_id\": \"INT\", \"content\": \"VARCHAR(500)\"}}}",
|
||||
"judgerAvailable": true,
|
||||
"judgeType": "large",
|
||||
"mysqlSchemas": [
|
||||
"Create table If Not Exists Tweets(tweet_id int, content varchar(500))",
|
||||
"Truncate table Tweets",
|
||||
"insert into Tweets (tweet_id, content) values ('1', 'What an amazing meal @MaxPower @AlexJones @JohnDoe #Learning #Fitness #Love')",
|
||||
"insert into Tweets (tweet_id, content) values ('2', 'Learning something new every day @AnnaWilson #Learning #Foodie')",
|
||||
"insert into Tweets (tweet_id, content) values ('3', 'Never been happier about today's achievements @SaraJohnson @JohnDoe @AnnaWilson #Fashion')",
|
||||
"insert into Tweets (tweet_id, content) values ('4', 'Traveling, exploring, and living my best life @JaneSmith @JohnDoe @ChrisAnderson @AlexJones #WorkLife #Travel')",
|
||||
"insert into Tweets (tweet_id, content) values ('5', 'Work hard, play hard, and cherish every moment @AlexJones #Fashion #Foodie')",
|
||||
"insert into Tweets (tweet_id, content) values ('6', 'Never been happier about today's achievements @ChrisAnderson #Fashion #WorkLife')",
|
||||
"insert into Tweets (tweet_id, content) values ('7', 'So grateful for today's experiences @AnnaWilson @LisaTaylor @ChrisAnderson @MikeBrown #Fashion #HappyDay #WorkLife #Nature')",
|
||||
"insert into Tweets (tweet_id, content) values ('8', 'What an amazing meal @EmilyClark @AlexJones @MikeBrown #Fitness')",
|
||||
"insert into Tweets (tweet_id, content) values ('9', 'Learning something new every day @EmilyClark @AnnaWilson @MaxPower #Travel')",
|
||||
"insert into Tweets (tweet_id, content) values ('10', 'So grateful for today's experiences @ChrisAnderson #Nature')",
|
||||
"insert into Tweets (tweet_id, content) values ('11', 'So grateful for today's experiences @AlexJones #Art #WorkLife')",
|
||||
"insert into Tweets (tweet_id, content) values ('12', 'Learning something new every day @JaneSmith @MikeBrown #Travel')",
|
||||
"insert into Tweets (tweet_id, content) values ('13', 'What an amazing meal @EmilyClark @JohnDoe @LisaTaylor @MaxPower #Foodie #Fitness')",
|
||||
"insert into Tweets (tweet_id, content) values ('14', 'Work hard, play hard, and cherish every moment @LisaTaylor @SaraJohnson @MaxPower @ChrisAnderson #TechLife #Nature #Music')",
|
||||
"insert into Tweets (tweet_id, content) values ('15', 'What a beautiful day it is @EmilyClark @MaxPower @SaraJohnson #Fashion')",
|
||||
"insert into Tweets (tweet_id, content) values ('16', 'What a beautiful day it is @AnnaWilson @JaneSmith #Fashion #Love #TechLife')"
|
||||
],
|
||||
"enableRunCode": true,
|
||||
"enableTestMode": false,
|
||||
"enableDebugger": false,
|
||||
"envInfo": "{\"mysql\": [\"MySQL\", \"<p><code>MySQL 8.0</code>.</p>\"], \"mssql\": [\"MS SQL Server\", \"<p><code>mssql server 2019</code>.</p>\"], \"oraclesql\": [\"Oracle\", \"<p><code>Oracle Sql 11.2</code>.</p>\"], \"pythondata\": [\"Pandas\", \"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0</p>\"], \"postgresql\": [\"PostgreSQL\", \"<p>PostgreSQL 16</p>\"]}",
|
||||
"libraryUrl": null,
|
||||
"adminUrl": null,
|
||||
"challengeQuestion": null,
|
||||
"__typename": "QuestionNode"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
174
leetcode/originData/check-if-grid-satisfies-conditions.json
Normal file
174
leetcode/originData/check-if-grid-satisfies-conditions.json
Normal file
File diff suppressed because one or more lines are too long
180
leetcode/originData/clear-digits.json
Normal file
180
leetcode/originData/clear-digits.json
Normal file
File diff suppressed because one or more lines are too long
179
leetcode/originData/count-pairs-that-form-a-complete-day-i.json
Normal file
179
leetcode/originData/count-pairs-that-form-a-complete-day-i.json
Normal file
File diff suppressed because one or more lines are too long
180
leetcode/originData/count-pairs-that-form-a-complete-day-ii.json
Normal file
180
leetcode/originData/count-pairs-that-form-a-complete-day-ii.json
Normal file
File diff suppressed because one or more lines are too long
175
leetcode/originData/count-the-number-of-inversions.json
Normal file
175
leetcode/originData/count-the-number-of-inversions.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
181
leetcode/originData/find-products-of-elements-of-big-array.json
Normal file
181
leetcode/originData/find-products-of-elements-of-big-array.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
191
leetcode/originData/find-the-n-th-value-after-k-seconds.json
Normal file
191
leetcode/originData/find-the-n-th-value-after-k-seconds.json
Normal file
File diff suppressed because one or more lines are too long
173
leetcode/originData/find-the-number-of-good-pairs-i.json
Normal file
173
leetcode/originData/find-the-number-of-good-pairs-i.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
180
leetcode/originData/maximum-difference-score-in-a-grid.json
Normal file
180
leetcode/originData/maximum-difference-score-in-a-grid.json
Normal file
File diff suppressed because one or more lines are too long
192
leetcode/originData/maximum-points-inside-the-square.json
Normal file
192
leetcode/originData/maximum-points-inside-the-square.json
Normal file
File diff suppressed because one or more lines are too long
180
leetcode/originData/maximum-prime-difference.json
Normal file
180
leetcode/originData/maximum-prime-difference.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
205
leetcode/originData/maximum-total-damage-with-spell-casting.json
Normal file
205
leetcode/originData/maximum-total-damage-with-spell-casting.json
Normal file
File diff suppressed because one or more lines are too long
176
leetcode/originData/maximum-total-reward-using-operations-i.json
Normal file
176
leetcode/originData/maximum-total-reward-using-operations-i.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
182
leetcode/originData/peaks-in-array.json
Normal file
182
leetcode/originData/peaks-in-array.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
167
leetcode/originData/special-array-i.json
Normal file
167
leetcode/originData/special-array-i.json
Normal file
File diff suppressed because one or more lines are too long
187
leetcode/originData/sum-of-digit-differences-of-all-pairs.json
Normal file
187
leetcode/originData/sum-of-digit-differences-of-all-pairs.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
167
leetcode/originData/valid-word.json
Normal file
167
leetcode/originData/valid-word.json
Normal file
File diff suppressed because one or more lines are too long
59
leetcode/problem/check-if-grid-satisfies-conditions.html
Normal file
59
leetcode/problem/check-if-grid-satisfies-conditions.html
Normal file
@ -0,0 +1,59 @@
|
||||
<p>You are given a 2D matrix <code>grid</code> of size <code>m x n</code>. You need to check if each cell <code>grid[i][j]</code> is:</p>
|
||||
|
||||
<ul>
|
||||
<li>Equal to the cell below it, i.e. <code>grid[i][j] == grid[i + 1][j]</code> (if it exists).</li>
|
||||
<li>Different from the cell to its right, i.e. <code>grid[i][j] != grid[i][j + 1]</code> (if it exists).</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <code>true</code> if <strong>all</strong> the cells satisfy these conditions, otherwise, return <code>false</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [[1,0,2],[1,0,2]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">true</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/04/15/examplechanged.png" style="width: 254px; height: 186px;padding: 10px; background: #fff; border-radius: .5rem;" /></strong></p>
|
||||
|
||||
<p>All the cells in the grid satisfy the conditions.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [[1,1,1],[0,0,0]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">false</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2024/03/27/example21.png" style="width: 254px; height: 186px;padding: 10px; background: #fff; border-radius: .5rem;" /></strong></p>
|
||||
|
||||
<p>All cells in the first row are equal.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [[1],[2],[3]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">false</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/31/changed.png" style="width: 86px; height: 277px;padding: 10px; background: #fff; border-radius: .5rem;" /></p>
|
||||
|
||||
<p>Cells in the first column have different values.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n, m <= 10</code></li>
|
||||
<li><code>0 <= grid[i][j] <= 9</code></li>
|
||||
</ul>
|
45
leetcode/problem/clear-digits.html
Normal file
45
leetcode/problem/clear-digits.html
Normal file
@ -0,0 +1,45 @@
|
||||
<p>You are given a string <code>s</code>.</p>
|
||||
|
||||
<p>Your task is to remove <strong>all</strong> digits by doing this operation repeatedly:</p>
|
||||
|
||||
<ul>
|
||||
<li>Delete the <em>first</em> digit and the <strong>closest</strong> <b>non-digit</b> character to its <em>left</em>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return the resulting string after removing all digits.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">s = "abc"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">"abc"</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There is no digit in the string.<!-- notionvc: ff07e34f-b1d6-41fb-9f83-5d0ba3c1ecde --></p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">s = "cb34"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">""</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>First, we apply the operation on <code>s[2]</code>, and <code>s</code> becomes <code>"c4"</code>.</p>
|
||||
|
||||
<p>Then we apply the operation on <code>s[1]</code>, and <code>s</code> becomes <code>""</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 100</code></li>
|
||||
<li><code>s</code> consists only of lowercase English letters and digits.</li>
|
||||
<li>The input is generated such that it is possible to delete all digits.</li>
|
||||
</ul>
|
38
leetcode/problem/count-pairs-that-form-a-complete-day-i.html
Normal file
38
leetcode/problem/count-pairs-that-form-a-complete-day-i.html
Normal file
@ -0,0 +1,38 @@
|
||||
<p>Given an integer array <code>hours</code> representing times in <strong>hours</strong>, return an integer denoting the number of pairs <code>i</code>, <code>j</code> where <code>i < j</code> and <code>hours[i] + hours[j]</code> forms a <strong>complete day</strong>.</p>
|
||||
|
||||
<p>A <strong>complete day</strong> is defined as a time duration that is an <strong>exact</strong> <strong>multiple</strong> of 24 hours.</p>
|
||||
|
||||
<p>For example, 1 day is 24 hours, 2 days is 48 hours, 3 days is 72 hours, and so on.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">hours = [12,12,30,24,24]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The pairs of indices that form a complete day are <code>(0, 1)</code> and <code>(3, 4)</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">hours = [72,48,24,3]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The pairs of indices that form a complete day are <code>(0, 1)</code>, <code>(0, 2)</code>, and <code>(1, 2)</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= hours.length <= 100</code></li>
|
||||
<li><code>1 <= hours[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,34 @@
|
||||
<p>Given an integer array <code>hours</code> representing times in <strong>hours</strong>, return an integer denoting the number of pairs <code>i</code>, <code>j</code> where <code>i < j</code> and <code>hours[i] + hours[j]</code> forms a <strong>complete day</strong>.</p>
|
||||
|
||||
<p>A <strong>complete day</strong> is defined as a time duration that is an <strong>exact</strong> <strong>multiple</strong> of 24 hours.</p>
|
||||
|
||||
<p>For example, 1 day is 24 hours, 2 days is 48 hours, 3 days is 72 hours, and so on.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">hours = [12,12,30,24,24]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> The pairs of indices that form a complete day are <code>(0, 1)</code> and <code>(3, 4)</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">hours = [72,48,24,3]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> The pairs of indices that form a complete day are <code>(0, 1)</code>, <code>(0, 2)</code>, and <code>(1, 2)</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= hours.length <= 5 * 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= hours[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
88
leetcode/problem/count-the-number-of-inversions.html
Normal file
88
leetcode/problem/count-the-number-of-inversions.html
Normal file
@ -0,0 +1,88 @@
|
||||
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p>
|
||||
|
||||
<p>A pair of indices <code>(i, j)</code> from an integer array <code>nums</code> is called an <strong>inversion</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>i < j</code> and <code>nums[i] > nums[j]</code></li>
|
||||
</ul>
|
||||
|
||||
<p>Return the number of <span data-keyword="permutation">permutations</span> <code>perm</code> of <code>[0, 1, 2, ..., n - 1]</code> such that for <strong>all</strong> <code>requirements[i]</code>, <code>perm[0..end<sub>i</sub>]</code> has exactly <code>cnt<sub>i</sub></code> inversions.</p>
|
||||
|
||||
<p>Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 3, requirements = [[2,2],[0,0]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The two permutations are:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>[2, 0, 1]</code>
|
||||
|
||||
<ul>
|
||||
<li>Prefix <code>[2, 0, 1]</code> has inversions <code>(0, 1)</code> and <code>(0, 2)</code>.</li>
|
||||
<li>Prefix <code>[2]</code> has 0 inversions.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><code>[1, 2, 0]</code>
|
||||
<ul>
|
||||
<li>Prefix <code>[1, 2, 0]</code> has inversions <code>(0, 2)</code> and <code>(1, 2)</code>.</li>
|
||||
<li>Prefix <code>[1]</code> has 0 inversions.</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 3, requirements = [[2,2],[1,1],[0,0]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> 1</p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The only satisfying permutation is <code>[2, 0, 1]</code>:</p>
|
||||
|
||||
<ul>
|
||||
<li>Prefix <code>[2, 0, 1]</code> has inversions <code>(0, 1)</code> and <code>(0, 2)</code>.</li>
|
||||
<li>Prefix <code>[2, 0]</code> has an inversion <code>(0, 1)</code>.</li>
|
||||
<li>Prefix <code>[2]</code> has 0 inversions.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 2, requirements = [[0,0],[1,0]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The only satisfying permutation is <code>[0, 1]</code>:</p>
|
||||
|
||||
<ul>
|
||||
<li>Prefix <code>[0]</code> has 0 inversions.</li>
|
||||
<li>Prefix <code>[0, 1]</code> has an inversion <code>(0, 1)</code>.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= n <= 300</code></li>
|
||||
<li><code>1 <= requirements.length <= n</code></li>
|
||||
<li><code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code></li>
|
||||
<li><code>0 <= end<sub>i</sub> <= n - 1</code></li>
|
||||
<li><code>0 <= cnt<sub>i</sub> <= 400</code></li>
|
||||
<li>The input is generated such that there is at least one <code>i</code> such that <code>end<sub>i</sub> == n - 1</code>.</li>
|
||||
<li>The input is generated such that all <code>end<sub>i</sub></code> are unique.</li>
|
||||
</ul>
|
@ -0,0 +1,38 @@
|
||||
<p>You are given an integer array <code>nums</code>. In one operation, you can add or subtract 1 from <strong>any</strong> element of <code>nums</code>.</p>
|
||||
|
||||
<p>Return the <strong>minimum</strong> number of operations to make all elements of <code>nums</code> divisible by 3.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>All array elements can be made divisible by 3 using 3 operations:</p>
|
||||
|
||||
<ul>
|
||||
<li>Subtract 1 from 1.</li>
|
||||
<li>Add 1 to 2.</li>
|
||||
<li>Subtract 1 from 4.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [3,6,9]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 50</code></li>
|
||||
<li><code>1 <= nums[i] <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,84 @@
|
||||
<p>You are given a <strong>non-negative</strong> integer <code>k</code>. There exists a staircase with an infinite number of stairs, with the <strong>lowest</strong> stair numbered 0.</p>
|
||||
|
||||
<p>Alice has an integer <code>jump</code>, with an initial value of 0. She starts on stair 1 and wants to reach stair <code>k</code> using <strong>any</strong> number of <strong>operations</strong>. If she is on stair <code>i</code>, in one <strong>operation</strong> she can:</p>
|
||||
|
||||
<ul>
|
||||
<li>Go down to stair <code>i - 1</code>. This operation <strong>cannot</strong> be used consecutively or on stair 0.</li>
|
||||
<li>Go up to stair <code>i + 2<sup>jump</sup></code>. And then, <code>jump</code> becomes <code>jump + 1</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return the <em>total</em> number of ways Alice can reach stair <code>k</code>.</p>
|
||||
|
||||
<p><strong>Note</strong> that it is possible that Alice reaches the stair <code>k</code>, and performs some operations to reach the stair <code>k</code> again.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">k = 0</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The 2 possible ways of reaching stair 0 are:</p>
|
||||
|
||||
<ul>
|
||||
<li>Alice starts at stair 1.
|
||||
<ul>
|
||||
<li>Using an operation of the first type, she goes down 1 stair to reach stair 0.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Alice starts at stair 1.
|
||||
<ul>
|
||||
<li>Using an operation of the first type, she goes down 1 stair to reach stair 0.</li>
|
||||
<li>Using an operation of the second type, she goes up 2<sup>0</sup> stairs to reach stair 1.</li>
|
||||
<li>Using an operation of the first type, she goes down 1 stair to reach stair 0.</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">k = 1</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">4</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The 4 possible ways of reaching stair 1 are:</p>
|
||||
|
||||
<ul>
|
||||
<li>Alice starts at stair 1. Alice is at stair 1.</li>
|
||||
<li>Alice starts at stair 1.
|
||||
<ul>
|
||||
<li>Using an operation of the first type, she goes down 1 stair to reach stair 0.</li>
|
||||
<li>Using an operation of the second type, she goes up 2<sup>0</sup> stairs to reach stair 1.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Alice starts at stair 1.
|
||||
<ul>
|
||||
<li>Using an operation of the second type, she goes up 2<sup>0</sup> stairs to reach stair 2.</li>
|
||||
<li>Using an operation of the first type, she goes down 1 stair to reach stair 1.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Alice starts at stair 1.
|
||||
<ul>
|
||||
<li>Using an operation of the first type, she goes down 1 stair to reach stair 0.</li>
|
||||
<li>Using an operation of the second type, she goes up 2<sup>0</sup> stairs to reach stair 1.</li>
|
||||
<li>Using an operation of the first type, she goes down 1 stair to reach stair 0.</li>
|
||||
<li>Using an operation of the second type, she goes up 2<sup>1</sup> stairs to reach stair 2.</li>
|
||||
<li>Using an operation of the first type, she goes down 1 stair to reach stair 1.</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= k <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,46 @@
|
||||
<p>You are given an integer array <code>nums</code>, an integer array <code>queries</code>, and an integer <code>x</code>.</p>
|
||||
|
||||
<p>For each <code>queries[i]</code>, you need to find the index of the <code>queries[i]<sup>th</sup></code> occurrence of <code>x</code> in the <code>nums</code> array. If there are fewer than <code>queries[i]</code> occurrences of <code>x</code>, the answer should be -1 for that query.</p>
|
||||
|
||||
<p>Return an integer array <code>answer</code> containing the answers to all queries.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,3,1,7], queries = [1,3,2,4], x = 1</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">[0,-1,2,-1]</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>For the 1<sup>st</sup> query, the first occurrence of 1 is at index 0.</li>
|
||||
<li>For the 2<sup>nd</sup> query, there are only two occurrences of 1 in <code>nums</code>, so the answer is -1.</li>
|
||||
<li>For the 3<sup>rd</sup> query, the second occurrence of 1 is at index 2.</li>
|
||||
<li>For the 4<sup>th</sup> query, there are only two occurrences of 1 in <code>nums</code>, so the answer is -1.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3], queries = [10], x = 5</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">[-1]</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>For the 1<sup>st</sup> query, 5 doesn't exist in <code>nums</code>, so the answer is -1.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length, queries.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= queries[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i], x <= 10<sup>4</sup></code></li>
|
||||
</ul>
|
48
leetcode/problem/find-products-of-elements-of-big-array.html
Normal file
48
leetcode/problem/find-products-of-elements-of-big-array.html
Normal file
@ -0,0 +1,48 @@
|
||||
<p>A <strong>powerful array</strong> for an integer <code>x</code> is the shortest sorted array of powers of two that sum up to <code>x</code>. For example, the powerful array for 11 is <code>[1, 2, 8]</code>.</p>
|
||||
|
||||
<p>The array <code>big_nums</code> is created by concatenating the <strong>powerful</strong> arrays for every positive integer <code>i</code> in ascending order: 1, 2, 3, and so forth. Thus, <code>big_nums</code> starts as <code>[<u>1</u>, <u>2</u>, <u>1, 2</u>, <u>4</u>, <u>1, 4</u>, <u>2, 4</u>, <u>1, 2, 4</u>, <u>8</u>, ...]</code>.</p>
|
||||
|
||||
<p>You are given a 2D integer matrix <code>queries</code>, where for <code>queries[i] = [from<sub>i</sub>, to<sub>i</sub>, mod<sub>i</sub>]</code> you should calculate <code>(big_nums[from<sub>i</sub>] * big_nums[from<sub>i</sub> + 1] * ... * big_nums[to<sub>i</sub>]) % mod<sub>i</sub></code><!-- notionvc: a71131cc-7b52-4786-9a4b-660d6d864f89 -->.</p>
|
||||
|
||||
<p>Return an integer array <code>answer</code> such that <code>answer[i]</code> is the answer to the <code>i<sup>th</sup></code> query.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">queries = [[1,3,7]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">[4]</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There is one query.</p>
|
||||
|
||||
<p><code>big_nums[1..3] = [2,1,2]</code>. The product of them is 4. The remainder of 4 under 7 is 4.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">queries = [[2,5,3],[7,7,4]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">[2,2]</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There are two queries.</p>
|
||||
|
||||
<p>First query: <code>big_nums[2..5] = [1,2,4,1]</code>. The product of them is 8. The remainder of 8 under 3 is 2.</p>
|
||||
|
||||
<p>Second query: <code>big_nums[7] = 2</code>. The remainder of 2 under 4 is 2.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= queries.length <= 500</code></li>
|
||||
<li><code>queries[i].length == 3</code></li>
|
||||
<li><code>0 <= queries[i][0] <= queries[i][1] <= 10<sup>15</sup></code></li>
|
||||
<li><code>1 <= queries[i][2] <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,51 @@
|
||||
<p>You are given an array <code>nums</code> and an integer <code>k</code>. You need to find a <span data-keyword="subarray-nonempty">subarray</span> of <code>nums</code> such that the <strong>absolute difference</strong> between <code>k</code> and the bitwise <code>OR</code> of the subarray elements is as<strong> small</strong> as possible. In other words, select a subarray <code>nums[l..r]</code> such that <code>|k - (nums[l] OR nums[l + 1] ... OR nums[r])|</code> is minimum.</p>
|
||||
|
||||
<p>Return the <strong>minimum</strong> possible value of the absolute difference.</p>
|
||||
|
||||
<p>A <strong>subarray</strong> is a contiguous <b>non-empty</b> sequence of elements within an array.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,4,5], k = 3</span></p>
|
||||
|
||||
<p><strong>Output:</strong> 0</p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The subarray <code>nums[0..1]</code> has <code>OR</code> value 3, which gives the minimum absolute difference <code>|3 - 3| = 0</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,3,1,3], k = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> 1</p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The subarray <code>nums[1..1]</code> has <code>OR</code> value 3, which gives the minimum absolute difference <code>|3 - 2| = 1</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1], k = 10</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">9</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There is a single subarray with <code>OR</code> value 1, which gives the minimum absolute difference <code>|10 - 1| = 9</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>1 <= k <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,135 @@
|
||||
<p>You are given two <strong>positive</strong> integers <code>n</code> and <code>k</code>. There are <code>n</code> children numbered from <code>0</code> to <code>n - 1</code> standing in a queue <em>in order</em> from left to right.</p>
|
||||
|
||||
<p>Initially, child 0 holds a ball and the direction of passing the ball is towards the right direction. After each second, the child holding the ball passes it to the child next to them. Once the ball reaches <strong>either</strong> end of the line, i.e. child 0 or child <code>n - 1</code>, the direction of passing is <strong>reversed</strong>.</p>
|
||||
|
||||
<p>Return the number of the child who receives the ball after <code>k</code> seconds.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 3, k = 5</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Time elapsed</th>
|
||||
<th>Children</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>0</code></td>
|
||||
<td><code>[<u>0</u>, 1, 2]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>1</code></td>
|
||||
<td><code>[0, <u>1</u>, 2]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>2</code></td>
|
||||
<td><code>[0, 1, <u>2</u>]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>3</code></td>
|
||||
<td><code>[0, <u>1</u>, 2]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>4</code></td>
|
||||
<td><code>[<u>0</u>, 1, 2]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>5</code></td>
|
||||
<td><code>[0, <u>1</u>, 2]</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 5, k = 6</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Time elapsed</th>
|
||||
<th>Children</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>0</code></td>
|
||||
<td><code>[<u>0</u>, 1, 2, 3, 4]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>1</code></td>
|
||||
<td><code>[0, <u>1</u>, 2, 3, 4]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>2</code></td>
|
||||
<td><code>[0, 1, <u>2</u>, 3, 4]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>3</code></td>
|
||||
<td><code>[0, 1, 2, <u>3</u>, 4]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>4</code></td>
|
||||
<td><code>[0, 1, 2, 3, <u>4</u>]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>5</code></td>
|
||||
<td><code>[0, 1, 2, <u>3</u>, 4]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>6</code></td>
|
||||
<td><code>[0, 1, <u>2</u>, 3, 4]</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 4, k = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Time elapsed</th>
|
||||
<th>Children</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>0</code></td>
|
||||
<td><code>[<u>0</u>, 1, 2, 3]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>1</code></td>
|
||||
<td><code>[0, <u>1</u>, 2, 3]</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>2</code></td>
|
||||
<td><code>[0, 1, <u>2</u>, 3]</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= n <= 50</code></li>
|
||||
<li><code>1 <= k <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,68 @@
|
||||
<p>A competition consists of <code>n</code> players numbered from <code>0</code> to <code>n - 1</code>.</p>
|
||||
|
||||
<p>You are given an integer array <code>skills</code> of size <code>n</code> and a <strong>positive</strong> integer <code>k</code>, where <code>skills[i]</code> is the skill level of player <code>i</code>. All integers in <code>skills</code> are <strong>unique</strong>.</p>
|
||||
|
||||
<p>All players are standing in a queue in order from player <code>0</code> to player <code>n - 1</code>.</p>
|
||||
|
||||
<p>The competition process is as follows:</p>
|
||||
|
||||
<ul>
|
||||
<li>The first two players in the queue play a game, and the player with the <strong>higher</strong> skill level wins.</li>
|
||||
<li>After the game, the winner stays at the beginning of the queue, and the loser goes to the end of it.</li>
|
||||
</ul>
|
||||
|
||||
<p>The winner of the competition is the <strong>first</strong> player who wins <code>k</code> games <strong>in a row</strong>.</p>
|
||||
|
||||
<p>Return the initial index of the <em>winning</em> player.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">skills = [4,2,6,3,9], k = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> 2</p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>Initially, the queue of players is <code>[0,1,2,3,4]</code>. The following process happens:</p>
|
||||
|
||||
<ul>
|
||||
<li>Players 0 and 1 play a game, since the skill of player 0 is higher than that of player 1, player 0 wins. The resulting queue is <code>[0,2,3,4,1]</code>.</li>
|
||||
<li>Players 0 and 2 play a game, since the skill of player 2 is higher than that of player 0, player 2 wins. The resulting queue is <code>[2,3,4,1,0]</code>.</li>
|
||||
<li>Players 2 and 3 play a game, since the skill of player 2 is higher than that of player 3, player 2 wins. The resulting queue is <code>[2,4,1,0,3]</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Player 2 won <code>k = 2</code> games in a row, so the winner is player 2.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">skills = [2,5,4], k = 3</span></p>
|
||||
|
||||
<p><strong>Output:</strong> 1</p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>Initially, the queue of players is <code>[0,1,2]</code>. The following process happens:</p>
|
||||
|
||||
<ul>
|
||||
<li>Players 0 and 1 play a game, since the skill of player 1 is higher than that of player 0, player 1 wins. The resulting queue is <code>[1,2,0]</code>.</li>
|
||||
<li>Players 1 and 2 play a game, since the skill of player 1 is higher than that of player 2, player 1 wins. The resulting queue is <code>[1,0,2]</code>.</li>
|
||||
<li>Players 1 and 0 play a game, since the skill of player 1 is higher than that of player 0, player 1 wins. The resulting queue is <code>[1,2,0]</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Player 1 won <code>k = 3</code> games in a row, so the winner is player 1.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>n == skills.length</code></li>
|
||||
<li><code>2 <= n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= k <= 10<sup>9</sup></code></li>
|
||||
<li><code>1 <= skills[i] <= 10<sup>6</sup></code></li>
|
||||
<li>All integers in <code>skills</code> are unique.</li>
|
||||
</ul>
|
@ -0,0 +1,37 @@
|
||||
<p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <code>seq[i] != seq[i + 1]</code>.</p>
|
||||
|
||||
<p>Return the <strong>maximum</strong> possible length of a <strong>good</strong> <span data-keyword="subsequence-array">subsequence</span> of <code>nums</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,1,1,3], k = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">4</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The maximum length subsequence is <code>[<u>1</u>,<u>2</u>,<u>1</u>,<u>1</u>,3]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4,5,1], k = 0</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The maximum length subsequence is <code>[<u>1</u>,2,3,4,5,<u>1</u>]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 500</code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= k <= min(nums.length, 25)</code></li>
|
||||
</ul>
|
@ -0,0 +1,37 @@
|
||||
<p>You are given an integer array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>. A sequence of integers <code>seq</code> is called <strong>good</strong> if there are <strong>at most</strong> <code>k</code> indices <code>i</code> in the range <code>[0, seq.length - 2]</code> such that <code>seq[i] != seq[i + 1]</code>.</p>
|
||||
|
||||
<p>Return the <strong>maximum</strong> possible length of a <strong>good</strong> <span data-keyword="subsequence-array">subsequence</span> of <code>nums</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,1,1,3], k = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">4</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The maximum length subsequence is <code>[<u>1</u>,<u>2</u>,<u>1</u>,<u>1</u>,3]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4,5,1], k = 0</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The maximum length subsequence is <code>[<u>1</u>,2,3,4,5,<u>1</u>]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 5 * 10<sup>3</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>0 <= k <= min(50, nums.length)</code></li>
|
||||
</ul>
|
@ -0,0 +1,41 @@
|
||||
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1's in <code>grid</code> lie inside this rectangle.</p>
|
||||
|
||||
<p>Return the <strong>minimum</strong> possible area of the rectangle.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [[0,1,0],[1,0,1]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">6</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/08/examplerect0.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 279px; height: 198px;" /></p>
|
||||
|
||||
<p>The smallest rectangle has a height of 2 and a width of 3, so it has an area of <code>2 * 3 = 6</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [[1,0],[0,0]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/08/examplerect1.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 204px; height: 201px;" /></p>
|
||||
|
||||
<p>The smallest rectangle has both height and width 1, so its area is <code>1 * 1 = 1</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= grid.length, grid[i].length <= 1000</code></li>
|
||||
<li><code>grid[i][j]</code> is either 0 or 1.</li>
|
||||
<li>The input is generated such that there is at least one 1 in <code>grid</code>.</li>
|
||||
</ul>
|
@ -0,0 +1,51 @@
|
||||
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. You need to find 3 <strong>non-overlapping</strong> rectangles having <strong>non-zero</strong> areas with horizontal and vertical sides such that all the 1's in <code>grid</code> lie inside these rectangles.</p>
|
||||
|
||||
<p>Return the <strong>minimum</strong> possible sum of the area of these rectangles.</p>
|
||||
|
||||
<p><strong>Note</strong> that the rectangles are allowed to touch.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [[1,0,1],[1,1,1]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">5</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/14/example0rect21.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 280px; height: 198px;" /></p>
|
||||
|
||||
<ul>
|
||||
<li>The 1's at <code>(0, 0)</code> and <code>(1, 0)</code> are covered by a rectangle of area 2.</li>
|
||||
<li>The 1's at <code>(0, 2)</code> and <code>(1, 2)</code> are covered by a rectangle of area 2.</li>
|
||||
<li>The 1 at <code>(1, 1)</code> is covered by a rectangle of area 1.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [[1,0,1,0],[0,1,0,1]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">5</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/14/example1rect2.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 356px; height: 198px;" /></p>
|
||||
|
||||
<ul>
|
||||
<li>The 1's at <code>(0, 0)</code> and <code>(0, 2)</code> are covered by a rectangle of area 3.</li>
|
||||
<li>The 1 at <code>(1, 1)</code> is covered by a rectangle of area 1.</li>
|
||||
<li>The 1 at <code>(1, 3)</code> is covered by a rectangle of area 1.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= grid.length, grid[i].length <= 30</code></li>
|
||||
<li><code>grid[i][j]</code> is either 0 or 1.</li>
|
||||
<li>The input is generated such that there are at least three 1's in <code>grid</code>.</li>
|
||||
</ul>
|
93
leetcode/problem/find-the-n-th-value-after-k-seconds.html
Normal file
93
leetcode/problem/find-the-n-th-value-after-k-seconds.html
Normal file
@ -0,0 +1,93 @@
|
||||
<p>You are given two integers <code>n</code> and <code>k</code>.</p>
|
||||
|
||||
<p>Initially, you start with an array <code>a</code> of <code>n</code> integers where <code>a[i] = 1</code> for all <code>0 <= i <= n - 1</code>. After each second, you simultaneously update each element to be the sum of all its preceding elements plus the element itself. For example, after one second, <code>a[0]</code> remains the same, <code>a[1]</code> becomes <code>a[0] + a[1]</code>, <code>a[2]</code> becomes <code>a[0] + a[1] + a[2]</code>, and so on.</p>
|
||||
|
||||
<p>Return the <strong>value</strong> of <code>a[n - 1]</code> after <code>k</code> seconds.</p>
|
||||
|
||||
<p>Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 4, k = 5</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">56</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<table border="1">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Second</th>
|
||||
<th>State After</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>0</td>
|
||||
<td>[1,1,1,1]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>[1,2,3,4]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>[1,3,6,10]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3</td>
|
||||
<td>[1,4,10,20]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>4</td>
|
||||
<td>[1,5,15,35]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>5</td>
|
||||
<td>[1,6,21,56]</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">n = 5, k = 3</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">35</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<table border="1">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Second</th>
|
||||
<th>State After</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>0</td>
|
||||
<td>[1,1,1,1,1]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>[1,2,3,4,5]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>[1,3,6,10,15]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3</td>
|
||||
<td>[1,4,10,20,35]</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n, k <= 1000</code></li>
|
||||
</ul>
|
37
leetcode/problem/find-the-number-of-good-pairs-i.html
Normal file
37
leetcode/problem/find-the-number-of-good-pairs-i.html
Normal file
@ -0,0 +1,37 @@
|
||||
<p>You are given 2 integer arrays <code>nums1</code> and <code>nums2</code> of lengths <code>n</code> and <code>m</code> respectively. You are also given a <strong>positive</strong> integer <code>k</code>.</p>
|
||||
|
||||
<p>A pair <code>(i, j)</code> is called <strong>good</strong> if <code>nums1[i]</code> is divisible by <code>nums2[j] * k</code> (<code>0 <= i <= n - 1</code>, <code>0 <= j <= m - 1</code>).</p>
|
||||
|
||||
<p>Return the total number of <strong>good</strong> pairs.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums1 = [1,3,4], nums2 = [1,3,4], k = 1</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">5</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
The 5 good pairs are <code>(0, 0)</code>, <code>(1, 0)</code>, <code>(1, 1)</code>, <code>(2, 0)</code>, and <code>(2, 2)</code>.</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums1 = [1,2,4,12], nums2 = [2,4], k = 3</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The 2 good pairs are <code>(3, 0)</code> and <code>(3, 1)</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n, m <= 50</code></li>
|
||||
<li><code>1 <= nums1[i], nums2[j] <= 50</code></li>
|
||||
<li><code>1 <= k <= 50</code></li>
|
||||
</ul>
|
@ -0,0 +1,49 @@
|
||||
<p>You are given an array <code>nums</code>, where each number in the array appears <strong>either</strong><em> </em>once<em> </em>or<em> </em>twice.</p>
|
||||
|
||||
<p>Return the bitwise<em> </em><code>XOR</code> of all the numbers that appear twice in the array, or 0 if no number appears twice.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,1,3]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The only number that appears twice in <code>nums</code> is 1.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>No number appears twice in <code>nums</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,2,1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>Numbers 1 and 2 appeared twice. <code>1 XOR 2 == 3</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 50</code></li>
|
||||
<li><code>1 <= nums[i] <= 50</code></li>
|
||||
<li>Each number in <code>nums</code> appears either once or twice.</li>
|
||||
</ul>
|
@ -0,0 +1,72 @@
|
||||
<p>You are given an integer array <code>nums</code> with length <code>n</code>.</p>
|
||||
|
||||
<p>The <strong>cost</strong> of a <span data-keyword="subarray-nonempty">subarray</span> <code>nums[l..r]</code>, where <code>0 <= l <= r < n</code>, is defined as:</p>
|
||||
|
||||
<p><code>cost(l, r) = nums[l] - nums[l + 1] + ... + nums[r] * (−1)<sup>r − l</sup></code></p>
|
||||
|
||||
<p>Your task is to <strong>split</strong> <code>nums</code> into subarrays such that the <strong>total</strong> <strong>cost</strong> of the subarrays is <strong>maximized</strong>, ensuring each element belongs to <strong>exactly one</strong> subarray.</p>
|
||||
|
||||
<p>Formally, if <code>nums</code> is split into <code>k</code> subarrays, where <code>k > 1</code>, at indices <code>i<sub>1</sub>, i<sub>2</sub>, ..., i<sub>k − 1</sub></code>, where <code>0 <= i<sub>1</sub> < i<sub>2</sub> < ... < i<sub>k - 1</sub> < n - 1</code>, then the total cost will be:</p>
|
||||
|
||||
<p><code>cost(0, i<sub>1</sub>) + cost(i<sub>1</sub> + 1, i<sub>2</sub>) + ... + cost(i<sub>k − 1</sub> + 1, n − 1)</code></p>
|
||||
|
||||
<p>Return an integer denoting the <em>maximum total cost</em> of the subarrays after splitting the array optimally.</p>
|
||||
|
||||
<p><strong>Note:</strong> If <code>nums</code> is not split into subarrays, i.e. <code>k = 1</code>, the total cost is simply <code>cost(0, n - 1)</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,-2,3,4]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">10</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>One way to maximize the total cost is by splitting <code>[1, -2, 3, 4]</code> into subarrays <code>[1, -2, 3]</code> and <code>[4]</code>. The total cost will be <code>(1 + 2 + 3) + 4 = 10</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,-1,1,-1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">4</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>One way to maximize the total cost is by splitting <code>[1, -1, 1, -1]</code> into subarrays <code>[1, -1]</code> and <code>[1, -1]</code>. The total cost will be <code>(1 + 1) + (1 + 1) = 4</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [0]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> 0</p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>We cannot split the array further, so the answer is 0.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 4:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,-1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>Selecting the whole array gives a total cost of <code>1 + 1 = 2</code>, which is the maximum.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
42
leetcode/problem/maximum-difference-score-in-a-grid.html
Normal file
42
leetcode/problem/maximum-difference-score-in-a-grid.html
Normal file
@ -0,0 +1,42 @@
|
||||
<p>You are given an <code>m x n</code> matrix <code>grid</code> consisting of <strong>positive</strong> integers. You can move from a cell in the matrix to <strong>any</strong> other cell that is either to the bottom or to the right (not necessarily adjacent). The score of a move from a cell with the value <code>c1</code> to a cell with the value <code>c2</code> is <code>c2 - c1</code>.<!-- notionvc: 8819ca04-8606-4ecf-815b-fb77bc63b851 --></p>
|
||||
|
||||
<p>You can start at <strong>any</strong> cell, and you have to make <strong>at least</strong> one move.</p>
|
||||
|
||||
<p>Return the <strong>maximum</strong> total score you can achieve.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
<img alt="" src="https://assets.leetcode.com/uploads/2024/03/14/grid1.png" style="width: 240px; height: 240px;" />
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [[9,5,7,3],[8,9,6,1],[6,7,14,3],[2,5,3,1]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">9</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> We start at the cell <code>(0, 1)</code>, and we perform the following moves:<br />
|
||||
- Move from the cell <code>(0, 1)</code> to <code>(2, 1)</code> with a score of <code>7 - 5 = 2</code>.<br />
|
||||
- Move from the cell <code>(2, 1)</code> to <code>(2, 2)</code> with a score of <code>14 - 7 = 7</code>.<br />
|
||||
The total score is <code>2 + 7 = 9</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/04/08/moregridsdrawio-1.png" style="width: 180px; height: 116px;" /></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">grid = [[4,3,2],[3,2,1]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">-1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> We start at the cell <code>(0, 0)</code>, and we perform one move: <code>(0, 0)</code> to <code>(0, 1)</code>. The score is <code>3 - 4 = -1</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>m == grid.length</code></li>
|
||||
<li><code>n == grid[i].length</code></li>
|
||||
<li><code>2 <= m, n <= 1000</code></li>
|
||||
<li><code>4 <= m * n <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= grid[i][j] <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
65
leetcode/problem/maximum-points-inside-the-square.html
Normal file
65
leetcode/problem/maximum-points-inside-the-square.html
Normal file
@ -0,0 +1,65 @@
|
||||
<p>You are given a 2D<strong> </strong>array <code>points</code> and a string <code>s</code> where, <code>points[i]</code> represents the coordinates of point <code>i</code>, and <code>s[i]</code> represents the <strong>tag</strong> of point <code>i</code>.</p>
|
||||
|
||||
<p>A <strong>valid</strong> square is a square centered at the origin <code>(0, 0)</code>, has edges parallel to the axes, and <strong>does not</strong> contain two points with the same tag.</p>
|
||||
|
||||
<p>Return the <strong>maximum</strong> number of points contained in a <strong>valid</strong> square.</p>
|
||||
|
||||
<p>Note:</p>
|
||||
|
||||
<ul>
|
||||
<li>A point is considered to be inside the square if it lies on or within the square's boundaries.</li>
|
||||
<li>The side length of the square can be zero.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/29/3708-tc1.png" style="width: 303px; height: 303px;" /></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">points = [[2,2],[-1,-2],[-4,4],[-3,1],[3,-3]], s = "abdca"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The square of side length 4 covers two points <code>points[0]</code> and <code>points[1]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/03/29/3708-tc2.png" style="width: 302px; height: 302px;" /></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">points = [[1,1],[-2,-2],[-2,2]], s = "abb"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The square of side length 2 covers one point, which is <code>points[0]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">points = [[1,1],[-1,-1],[2,-2]], s = "ccd"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>It's impossible to make any valid squares centered at the origin such that it covers only one point among <code>points[0]</code> and <code>points[1]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length, points.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>points[i].length == 2</code></li>
|
||||
<li><code>-10<sup>9</sup> <= points[i][0], points[i][1] <= 10<sup>9</sup></code></li>
|
||||
<li><code>s.length == points.length</code></li>
|
||||
<li><code>points</code> consists of distinct coordinates.</li>
|
||||
<li><code>s</code> consists only of lowercase English letters.</li>
|
||||
</ul>
|
33
leetcode/problem/maximum-prime-difference.html
Normal file
33
leetcode/problem/maximum-prime-difference.html
Normal file
@ -0,0 +1,33 @@
|
||||
<p>You are given an integer array <code>nums</code>.</p>
|
||||
|
||||
<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [4,2,9,5,3]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> <code>nums[1]</code>, <code>nums[3]</code>, and <code>nums[4]</code> are prime. So the answer is <code>|4 - 1| = 3</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [4,8,2,8]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> <code>nums[2]</code> is prime. Because there is just one prime number, the answer is <code>|2 - 2| = 0</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 3 * 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 100</code></li>
|
||||
<li>The input is generated such that the number of prime numbers in the <code>nums</code> is at least one.</li>
|
||||
</ul>
|
@ -0,0 +1,45 @@
|
||||
<p>You are given an array <code>nums</code> consisting of integers. You are also given a 2D array <code>queries</code>, where <code>queries[i] = [pos<sub>i</sub>, x<sub>i</sub>]</code>.</p>
|
||||
|
||||
<p>For query <code>i</code>, we first set <code>nums[pos<sub>i</sub>]</code> equal to <code>x<sub>i</sub></code>, then we calculate the answer to query <code>i</code> which is the <strong>maximum</strong> sum of a <span data-keyword="subsequence-array">subsequence</span> of <code>nums</code> where <strong>no two adjacent elements are selected</strong>.</p>
|
||||
|
||||
<p>Return the <em>sum</em> of the answers to all queries.</p>
|
||||
|
||||
<p>Since the final answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
|
||||
|
||||
<p>A <strong>subsequence</strong> is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [3,5,9], queries = [[1,-2],[0,-3]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">21</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong><br />
|
||||
After the 1<sup>st</sup> query, <code>nums = [3,-2,9]</code> and the maximum sum of a subsequence with non-adjacent elements is <code>3 + 9 = 12</code>.<br />
|
||||
After the 2<sup>nd</sup> query, <code>nums = [-3,-2,9]</code> and the maximum sum of a subsequence with non-adjacent elements is 9.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [0,-1], queries = [[0,-5]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong><br />
|
||||
After the 1<sup>st</sup> query, <code>nums = [-5,-1]</code> and the maximum sum of a subsequence with non-adjacent elements is 0 (choosing an empty subsequence).</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>-10<sup>5</sup> <= nums[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= queries.length <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>queries[i] == [pos<sub>i</sub>, x<sub>i</sub>]</code></li>
|
||||
<li><code>0 <= pos<sub>i</sub> <= nums.length - 1</code></li>
|
||||
<li><code>-10<sup>5</sup> <= x<sub>i</sub> <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,42 @@
|
||||
<p>A magician has various spells.</p>
|
||||
|
||||
<p>You are given an array <code>power</code>, where each element represents the damage of a spell. Multiple spells can have the same damage value.</p>
|
||||
|
||||
<p>It is a known fact that if a magician decides to cast a spell with a damage of <code>power[i]</code>, they <strong>cannot</strong> cast any spell with a damage of <code>power[i] - 2</code>, <code>power[i] - 1</code>, <code>power[i] + 1</code>, or <code>power[i] + 2</code>.</p>
|
||||
|
||||
<p>Each spell can be cast <strong>only once</strong>.</p>
|
||||
|
||||
<p>Return the <strong>maximum</strong> possible <em>total damage</em> that a magician can cast.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">power = [1,1,3,4]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">6</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The maximum possible damage of 6 is produced by casting spells 0, 1, 3 with damage 1, 1, 4.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">power = [7,1,6,6]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">13</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The maximum possible damage of 13 is produced by casting spells 1, 2, 3 with damage 1, 6, 6.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= power.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= power[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,43 @@
|
||||
<p>You are given an integer array <code>rewardValues</code> of length <code>n</code>, representing the values of rewards.</p>
|
||||
|
||||
<p>Initially, your total reward <code>x</code> is 0, and all indices are <strong>unmarked</strong>. You are allowed to perform the following operation <strong>any</strong> number of times:</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose an <strong>unmarked</strong> index <code>i</code> from the range <code>[0, n - 1]</code>.</li>
|
||||
<li>If <code>rewardValues[i]</code> is <strong>greater</strong> than your current total reward <code>x</code>, then add <code>rewardValues[i]</code> to <code>x</code> (i.e., <code>x = x + rewardValues[i]</code>), and <strong>mark</strong> the index <code>i</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return an integer denoting the <strong>maximum </strong><em>total reward</em> you can collect by performing the operations optimally.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">rewardValues = [1,1,3,3]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">4</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>During the operations, we can choose to mark the indices 0 and 2 in order, and the total reward will be 4, which is the maximum.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">rewardValues = [1,6,4,3,2]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">11</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>Mark the indices 0, 2, and 1 in order. The total reward will then be 11, which is the maximum.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= rewardValues.length <= 2000</code></li>
|
||||
<li><code>1 <= rewardValues[i] <= 2000</code></li>
|
||||
</ul>
|
@ -0,0 +1,43 @@
|
||||
<p>You are given an integer array <code>rewardValues</code> of length <code>n</code>, representing the values of rewards.</p>
|
||||
|
||||
<p>Initially, your total reward <code>x</code> is 0, and all indices are <strong>unmarked</strong>. You are allowed to perform the following operation <strong>any</strong> number of times:</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose an <strong>unmarked</strong> index <code>i</code> from the range <code>[0, n - 1]</code>.</li>
|
||||
<li>If <code>rewardValues[i]</code> is <strong>greater</strong> than your current total reward <code>x</code>, then add <code>rewardValues[i]</code> to <code>x</code> (i.e., <code>x = x + rewardValues[i]</code>), and <strong>mark</strong> the index <code>i</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return an integer denoting the <strong>maximum </strong><em>total reward</em> you can collect by performing the operations optimally.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">rewardValues = [1,1,3,3]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">4</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>During the operations, we can choose to mark the indices 0 and 2 in order, and the total reward will be 4, which is the maximum.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">rewardValues = [1,6,4,3,2]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">11</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>Mark the indices 0, 2, and 1 in order. The total reward will then be 11, which is the maximum.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= rewardValues.length <= 5 * 10<sup>4</sup></code></li>
|
||||
<li><code>1 <= rewardValues[i] <= 5 * 10<sup>4</sup></code></li>
|
||||
</ul>
|
@ -0,0 +1,145 @@
|
||||
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p>
|
||||
|
||||
<p>You repeat the following procedure <code>n / 2</code> times:</p>
|
||||
|
||||
<ul>
|
||||
<li>Remove the <strong>smallest</strong> element, <code>minElement</code>, and the <strong>largest</strong> element <code>maxElement</code>, from <code>nums</code>.</li>
|
||||
<li>Add <code>(minElement + maxElement) / 2</code> to <code>averages</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return the <strong>minimum</strong> element in <code>averages</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [7,8,3,4,15,13,4,1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">5.5</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>step</th>
|
||||
<th>nums</th>
|
||||
<th>averages</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>0</td>
|
||||
<td>[7,8,3,4,15,13,4,1]</td>
|
||||
<td>[]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>[7,8,3,4,13,4]</td>
|
||||
<td>[8]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>[7,8,4,4]</td>
|
||||
<td>[8,8]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3</td>
|
||||
<td>[7,4]</td>
|
||||
<td>[8,8,6]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>4</td>
|
||||
<td>[]</td>
|
||||
<td>[8,8,6,5.5]</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
The smallest element of averages, 5.5, is returned.</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,9,8,3,10,5]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">5.5</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>step</th>
|
||||
<th>nums</th>
|
||||
<th>averages</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>0</td>
|
||||
<td><span class="example-io">[1,9,8,3,10,5]</span></td>
|
||||
<td>[]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td><span class="example-io">[9,8,3,5]</span></td>
|
||||
<td>[5.5]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td><span class="example-io">[8,5]</span></td>
|
||||
<td>[5.5,6]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3</td>
|
||||
<td>[]</td>
|
||||
<td>[5.5,6,6.5]</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,7,8,9]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">5.0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>step</th>
|
||||
<th>nums</th>
|
||||
<th>averages</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>0</td>
|
||||
<td><span class="example-io">[1,2,3,7,8,9]</span></td>
|
||||
<td>[]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td><span class="example-io">[2,3,7,8]</span></td>
|
||||
<td>[5]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td><span class="example-io">[3,7]</span></td>
|
||||
<td>[5,5]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3</td>
|
||||
<td><span class="example-io">[]</span></td>
|
||||
<td>[5,5,5]</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= n == nums.length <= 50</code></li>
|
||||
<li><code>n</code> is even.</li>
|
||||
<li><code>1 <= nums[i] <= 50</code></li>
|
||||
</ul>
|
178
leetcode/problem/minimum-number-of-chairs-in-a-waiting-room.html
Normal file
178
leetcode/problem/minimum-number-of-chairs-in-a-waiting-room.html
Normal file
@ -0,0 +1,178 @@
|
||||
<p>You are given a string <code>s</code>. Simulate events at each second <code>i</code>:</p>
|
||||
|
||||
<ul>
|
||||
<li>If <code>s[i] == 'E'</code>, a person enters the waiting room and takes one of the chairs in it.</li>
|
||||
<li>If <code>s[i] == 'L'</code>, a person leaves the waiting room, freeing up a chair.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return the <strong>minimum </strong>number of chairs needed so that a chair is available for every person who enters the waiting room given that it is initially <strong>empty</strong>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">s = "EEEEEEE"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">7</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>After each second, a person enters the waiting room and no person leaves it. Therefore, a minimum of 7 chairs is needed.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">s = "ELELEEL"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>Let's consider that there are 2 chairs in the waiting room. The table below shows the state of the waiting room at each second.</p>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Second</th>
|
||||
<th>Event</th>
|
||||
<th>People in the Waiting Room</th>
|
||||
<th>Available Chairs</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>0</td>
|
||||
<td>Enter</td>
|
||||
<td>1</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>Leave</td>
|
||||
<td>0</td>
|
||||
<td>2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>Enter</td>
|
||||
<td>1</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3</td>
|
||||
<td>Leave</td>
|
||||
<td>0</td>
|
||||
<td>2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>4</td>
|
||||
<td>Enter</td>
|
||||
<td>1</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>5</td>
|
||||
<td>Enter</td>
|
||||
<td>2</td>
|
||||
<td>0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>6</td>
|
||||
<td>Leave</td>
|
||||
<td>1</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">s = "ELEELEELLL"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>Let's consider that there are 3 chairs in the waiting room. The table below shows the state of the waiting room at each second.</p>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Second</th>
|
||||
<th>Event</th>
|
||||
<th>People in the Waiting Room</th>
|
||||
<th>Available Chairs</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>0</td>
|
||||
<td>Enter</td>
|
||||
<td>1</td>
|
||||
<td>2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>Leave</td>
|
||||
<td>0</td>
|
||||
<td>3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>2</td>
|
||||
<td>Enter</td>
|
||||
<td>1</td>
|
||||
<td>2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>3</td>
|
||||
<td>Enter</td>
|
||||
<td>2</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>4</td>
|
||||
<td>Leave</td>
|
||||
<td>1</td>
|
||||
<td>2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>5</td>
|
||||
<td>Enter</td>
|
||||
<td>2</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>6</td>
|
||||
<td>Enter</td>
|
||||
<td>3</td>
|
||||
<td>0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>7</td>
|
||||
<td>Leave</td>
|
||||
<td>2</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>8</td>
|
||||
<td>Leave</td>
|
||||
<td>1</td>
|
||||
<td>2</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>9</td>
|
||||
<td>Leave</td>
|
||||
<td>0</td>
|
||||
<td>3</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 50</code></li>
|
||||
<li><code>s</code> consists only of the letters <code>'E'</code> and <code>'L'</code>.</li>
|
||||
<li><code>s</code> represents a valid sequence of entries and exits.</li>
|
||||
</ul>
|
@ -0,0 +1,83 @@
|
||||
<p>You are given a string <code>word</code> of size <code>n</code>, and an integer <code>k</code> such that <code>k</code> divides <code>n</code>.</p>
|
||||
|
||||
<p>In one operation, you can pick any two indices <code>i</code> and <code>j</code>, that are divisible by <code>k</code>, then replace the <span data-keyword="substring">substring</span> of length <code>k</code> starting at <code>i</code> with the substring of length <code>k</code> starting at <code>j</code>. That is, replace the substring <code>word[i..i + k - 1]</code> with the substring <code>word[j..j + k - 1]</code>.<!-- notionvc: 49ac84f7-0724-452a-ab43-0c5e53f1db33 --></p>
|
||||
|
||||
<p>Return <em>the <strong>minimum</strong> number of operations required to make</em> <code>word</code> <em><strong>k-periodic</strong></em>.</p>
|
||||
|
||||
<p>We say that <code>word</code> is <strong>k-periodic</strong> if there is some string <code>s</code> of length <code>k</code> such that <code>word</code> can be obtained by concatenating <code>s</code> an arbitrary number of times. For example, if <code>word == “ababab”</code>, then <code>word</code> is 2-periodic for <code>s = "ab"</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">word = "leetcodeleet", k = 4</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>We can obtain a 4-periodic string by picking i = 4 and j = 0. After this operation, word becomes equal to "leetleetleet".</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">word = "</span>leetcoleet<span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
">", k = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong> 3</p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>We can obtain a 2-periodic string by applying the operations in the table below.</p>
|
||||
|
||||
<table border="1" bordercolor="#ccc" cellpadding="5" cellspacing="0" height="146" style="border-collapse:collapse; text-align: center; vertical-align: middle;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>i</th>
|
||||
<th>j</th>
|
||||
<th>word</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px 15px;">0</td>
|
||||
<td style="padding: 5px 15px;">2</td>
|
||||
<td style="padding: 5px 15px;">etetcoleet</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px 15px;">4</td>
|
||||
<td style="padding: 5px 15px;">0</td>
|
||||
<td style="padding: 5px 15px;">etetetleet</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 5px 15px;">6</td>
|
||||
<td style="padding: 5px 15px;">0</td>
|
||||
<td style="padding: 5px 15px;">etetetetet</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="gtx-trans" style="position: absolute; left: 107px; top: 238.5px;">
|
||||
<div class="gtx-trans-icon"> </div>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= n == word.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= k <= word.length</code></li>
|
||||
<li><code>k</code> divides <code>word.length</code>.</li>
|
||||
<li><code>word</code> consists only of lowercase English letters.</li>
|
||||
</ul>
|
@ -0,0 +1,48 @@
|
||||
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p>
|
||||
|
||||
<p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</strong> <strong>all</strong> of them.</li>
|
||||
</ul>
|
||||
|
||||
<p><strong>Flipping</strong> an element means changing its value from 0 to 1, and from 1 to 0.</p>
|
||||
|
||||
<p>Return the <strong>minimum</strong> number of operations required to make all elements in <code>nums</code> equal to 1. If it is impossible, return -1.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [0,1,1,1,0,0]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong><br />
|
||||
We can do the following operations:</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose the elements at indices 0, 1 and 2. The resulting array is <code>nums = [<u><strong>1</strong></u>,<u><strong>0</strong></u>,<u><strong>0</strong></u>,1,0,0]</code>.</li>
|
||||
<li>Choose the elements at indices 1, 2 and 3. The resulting array is <code>nums = [1,<u><strong>1</strong></u>,<u><strong>1</strong></u>,<strong><u>0</u></strong>,0,0]</code>.</li>
|
||||
<li>Choose the elements at indices 3, 4 and 5. The resulting array is <code>nums = [1,1,1,<strong><u>1</u></strong>,<u><strong>1</strong></u>,<u><strong>1</strong></u>]</code>.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [0,1,1,1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">-1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong><br />
|
||||
It is impossible to make all elements equal to 1.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>3 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= nums[i] <= 1</code></li>
|
||||
</ul>
|
@ -0,0 +1,53 @@
|
||||
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p>
|
||||
|
||||
<p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose <strong>any</strong> index <code>i</code> from the array and <strong>flip</strong> <strong>all</strong> the elements from index <code>i</code> to the end of the array.</li>
|
||||
</ul>
|
||||
|
||||
<p><strong>Flipping</strong> an element means changing its value from 0 to 1, and from 1 to 0.</p>
|
||||
|
||||
<p>Return the <strong>minimum</strong> number of operations required to make all elements in <code>nums</code> equal to 1.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [0,1,1,0,1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">4</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong><br />
|
||||
We can do the following operations:</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose the index <code>i = 1</code><span class="example-io">. The resulting array will be <code>nums = [0,<u><strong>0</strong></u>,<u><strong>0</strong></u>,<u><strong>1</strong></u>,<u><strong>0</strong></u>]</code>.</span></li>
|
||||
<li>Choose the index <code>i = 0</code><span class="example-io">. The resulting array will be <code>nums = [<u><strong>1</strong></u>,<u><strong>1</strong></u>,<u><strong>1</strong></u>,<u><strong>0</strong></u>,<u><strong>1</strong></u>]</code>.</span></li>
|
||||
<li>Choose the index <code>i = 4</code><span class="example-io">. The resulting array will be <code>nums = [1,1,1,0,<u><strong>0</strong></u>]</code>.</span></li>
|
||||
<li>Choose the index <code>i = 3</code><span class="example-io">. The resulting array will be <code>nums = [1,1,1,<u><strong>1</strong></u>,<u><strong>1</strong></u>]</code>.</span></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,0,0,0]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong><br />
|
||||
We can do the following operation:</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose the index <code>i = 1</code><span class="example-io">. The resulting array will be <code>nums = [1,<u><strong>1</strong></u>,<u><strong>1</strong></u>,<u><strong>1</strong></u>]</code>.</span></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= nums[i] <= 1</code></li>
|
||||
</ul>
|
65
leetcode/problem/peaks-in-array.html
Normal file
65
leetcode/problem/peaks-in-array.html
Normal file
@ -0,0 +1,65 @@
|
||||
<p>A <strong>peak</strong> in an array <code>arr</code> is an element that is <strong>greater</strong> than its previous and next element in <code>arr</code>.</p>
|
||||
|
||||
<p>You are given an integer array <code>nums</code> and a 2D integer array <code>queries</code>.</p>
|
||||
|
||||
<p>You have to process queries of two types:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>queries[i] = [1, l<sub>i</sub>, r<sub>i</sub>]</code>, determine the count of <strong>peak</strong> elements in the <span data-keyword="subarray">subarray</span> <code>nums[l<sub>i</sub>..r<sub>i</sub>]</code>.<!-- notionvc: 73b20b7c-e1ab-4dac-86d0-13761094a9ae --></li>
|
||||
<li><code>queries[i] = [2, index<sub>i</sub>, val<sub>i</sub>]</code>, change <code>nums[index<sub>i</sub>]</code> to <code><font face="monospace">val<sub>i</sub></font></code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return an array <code>answer</code> containing the results of the queries of the first type in order.<!-- notionvc: a9ccef22-4061-4b5a-b4cc-a2b2a0e12f30 --></p>
|
||||
|
||||
<p><strong>Notes:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The <strong>first</strong> and the <strong>last</strong> element of an array or a subarray<!-- notionvc: fcffef72-deb5-47cb-8719-3a3790102f73 --> <strong>cannot</strong> be a peak.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [3,1,4,2,5], queries = [[2,3,4],[1,0,4]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">[0]</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>First query: We change <code>nums[3]</code> to 4 and <code>nums</code> becomes <code>[3,1,4,4,5]</code>.</p>
|
||||
|
||||
<p>Second query: The number of peaks in the <code>[3,1,4,4,5]</code> is 0.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [4,1,4,2,1,5], queries = [[2,2,4],[1,0,2],[1,0,4]]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">[0,1]</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>First query: <code>nums[2]</code> should become 4, but it is already set to 4.</p>
|
||||
|
||||
<p>Second query: The number of peaks in the <code>[4,1,4]</code> is 0.</p>
|
||||
|
||||
<p>Third query: The second 4 is a peak in the <code>[4,1,4,2,1]</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>3 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= queries.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>queries[i][0] == 1</code> or <code>queries[i][0] == 2</code></li>
|
||||
<li>For all <code>i</code> that:
|
||||
<ul>
|
||||
<li><code>queries[i][0] == 1</code>: <code>0 <= queries[i][1] <= queries[i][2] <= nums.length - 1</code></li>
|
||||
<li><code>queries[i][0] == 2</code>: <code>0 <= queries[i][1] <= nums.length - 1</code>, <code>1 <= queries[i][2] <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
@ -0,0 +1,46 @@
|
||||
<p>You are given two strings <code>s</code> and <code>t</code> such that every character occurs at most once in <code>s</code> and <code>t</code> is a permutation of <code>s</code>.</p>
|
||||
|
||||
<p>The <strong>permutation difference</strong> between <code>s</code> and <code>t</code> is defined as the <strong>sum</strong> of the absolute difference between the index of the occurrence of each character in <code>s</code> and the index of the occurrence of the same character in <code>t</code>.</p>
|
||||
|
||||
<p>Return the <strong>permutation difference</strong> between <code>s</code> and <code>t</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">s = "abc", t = "bac"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">2</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>For <code>s = "abc"</code> and <code>t = "bac"</code>, the permutation difference of <code>s</code> and <code>t</code> is equal to the sum of:</p>
|
||||
|
||||
<ul>
|
||||
<li>The absolute difference between the index of the occurrence of <code>"a"</code> in <code>s</code> and the index of the occurrence of <code>"a"</code> in <code>t</code>.</li>
|
||||
<li>The absolute difference between the index of the occurrence of <code>"b"</code> in <code>s</code> and the index of the occurrence of <code>"b"</code> in <code>t</code>.</li>
|
||||
<li>The absolute difference between the index of the occurrence of <code>"c"</code> in <code>s</code> and the index of the occurrence of <code>"c"</code> in <code>t</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>That is, the permutation difference between <code>s</code> and <code>t</code> is equal to <code>|0 - 1| + |2 - 2| + |1 - 0| = 2</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">s = "abcde", t = "edbac"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">12</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> The permutation difference between <code>s</code> and <code>t</code> is equal to <code>|0 - 3| + |1 - 2| + |2 - 4| + |3 - 1| + |4 - 0| = 12</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= s.length <= 26</code></li>
|
||||
<li>Each character occurs at most once in <code>s</code>.</li>
|
||||
<li><code>t</code> is a permutation of <code>s</code>.</li>
|
||||
<li><code>s</code> consists only of lowercase English letters.</li>
|
||||
</ul>
|
48
leetcode/problem/special-array-i.html
Normal file
48
leetcode/problem/special-array-i.html
Normal file
@ -0,0 +1,48 @@
|
||||
<p>An array is considered <strong>special</strong> if every pair of its adjacent elements contains two numbers with different parity.<!-- notionvc: e6bed0fa-c67d-43a7-81b4-99fb85b99e98 --></p>
|
||||
|
||||
<p>You are given an array of integers <code>nums</code>. Return <code>true</code> if <code>nums</code> is a <strong>special</strong> array, otherwise, return <code>false</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">true</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There is only one element. So the answer is <code>true</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [2,1,4]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">true</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>There is only two pairs: <code>(2,1)</code> and <code>(1,4)</code>, and both of them contain numbers with different parity. So the answer is <code>true</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [4,3,1,6]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">false</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p><code>nums[1]</code> and <code>nums[2]</code> are both odd. So the answer is <code>false</code>.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 100</code></li>
|
||||
<li><code>1 <= nums[i] <= 100</code></li>
|
||||
</ul>
|
41
leetcode/problem/sum-of-digit-differences-of-all-pairs.html
Normal file
41
leetcode/problem/sum-of-digit-differences-of-all-pairs.html
Normal file
@ -0,0 +1,41 @@
|
||||
<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers where all integers have the <strong>same</strong> number of digits.</p>
|
||||
|
||||
<p>The <strong>digit difference</strong> between two integers is the <em>count</em> of different digits that are in the <strong>same</strong> position in the two integers.</p>
|
||||
|
||||
<p>Return the <strong>sum</strong> of the <strong>digit differences</strong> between <strong>all</strong> pairs of integers in <code>nums</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [13,23,12]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> 4</p>
|
||||
|
||||
<p><strong>Explanation:</strong><br />
|
||||
We have the following:<br />
|
||||
- The digit difference between <strong>1</strong>3 and <strong>2</strong>3 is 1.<br />
|
||||
- The digit difference between 1<strong>3</strong> and 1<strong>2</strong> is 1.<br />
|
||||
- The digit difference between <strong>23</strong> and <strong>12</strong> is 2.<br />
|
||||
So the total sum of digit differences between all pairs of integers is <code>1 + 1 + 2 = 4</code>.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [10,10,10,10]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong><br />
|
||||
All the integers in the array are the same. So the total sum of digit differences between all pairs of integers will be 0.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] < 10<sup>9</sup></code></li>
|
||||
<li>All integers in <code>nums</code> have the same number of digits.</li>
|
||||
</ul>
|
@ -0,0 +1,70 @@
|
||||
<p>In a mystic dungeon, <code>n</code> magicians are standing in a line. Each magician has an attribute that gives you energy. Some magicians can give you negative energy, which means taking energy from you.</p>
|
||||
|
||||
<p>You have been cursed in such a way that after absorbing energy from magician <code>i</code>, you will be instantly transported to magician <code>(i + k)</code>. This process will be repeated until you reach the magician where <code>(i + k)</code> does not exist.</p>
|
||||
|
||||
<p>In other words, you will choose a starting point and then teleport with <code>k</code> jumps until you reach the end of the magicians' sequence, <strong>absorbing all the energy</strong> during the journey.</p>
|
||||
|
||||
<p>You are given an array <code>energy</code> and an integer <code>k</code>. Return the <strong>maximum</strong> possible energy you can gain.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block" style="
|
||||
border-color: var(--border-tertiary);
|
||||
border-left-width: 2px;
|
||||
color: var(--text-secondary);
|
||||
font-size: .875rem;
|
||||
margin-bottom: 1rem;
|
||||
margin-top: 1rem;
|
||||
overflow: visible;
|
||||
padding-left: 1rem;
|
||||
">
|
||||
<p><strong>Input:</strong> <span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
"> energy = [5,2,-10,-5,1], k = 3</span></p>
|
||||
|
||||
<p><strong>Output:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
"> 3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> We can gain a total energy of 3 by starting from magician 1 absorbing 2 + 1 = 3.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block" style="
|
||||
border-color: var(--border-tertiary);
|
||||
border-left-width: 2px;
|
||||
color: var(--text-secondary);
|
||||
font-size: .875rem;
|
||||
margin-bottom: 1rem;
|
||||
margin-top: 1rem;
|
||||
overflow: visible;
|
||||
padding-left: 1rem;
|
||||
">
|
||||
<p><strong>Input:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
"> energy = [-2,-3,-1], k = 2</span></p>
|
||||
|
||||
<p><strong>Output:</strong><span class="example-io" style="
|
||||
font-family: Menlo,sans-serif;
|
||||
font-size: 0.85rem;
|
||||
"> -1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong> We can gain a total energy of -1 by starting from magician 2.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= energy.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>-1000 <= energy[i] <= 1000</code></li>
|
||||
<li><code>1 <= k <= energy.length - 1</code></li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
64
leetcode/problem/valid-word.html
Normal file
64
leetcode/problem/valid-word.html
Normal file
@ -0,0 +1,64 @@
|
||||
<p>A word is considered <strong>valid</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li>It contains a <strong>minimum</strong> of 3 characters.</li>
|
||||
<li>It contains only digits (0-9), and English letters (uppercase and lowercase).</li>
|
||||
<li>It includes <strong>at least</strong> one <strong>vowel</strong>.</li>
|
||||
<li>It includes <strong>at least</strong> one <strong>consonant</strong>.</li>
|
||||
</ul>
|
||||
|
||||
<p>You are given a string <code>word</code>.</p>
|
||||
|
||||
<p>Return <code>true</code> if <code>word</code> is valid, otherwise, return <code>false</code>.</p>
|
||||
|
||||
<p><strong>Notes:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'</code>, and their uppercases are <strong>vowels</strong>.</li>
|
||||
<li>A <strong>consonant</strong> is an English letter that is not a vowel.</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word = "234Adas"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">true</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>This word satisfies the conditions.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word = "b3"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">false</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The length of this word is fewer than 3, and does not have a vowel.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">word = "a3$e"</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">false</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>This word contains a <code>'$'</code> character and does not have a consonant.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word.length <= 20</code></li>
|
||||
<li><code>word</code> consists of English uppercase and lowercase letters, digits, <code>'@'</code>, <code>'#'</code>, and <code>'$'</code>.</li>
|
||||
</ul>
|
Loading…
Reference in New Issue
Block a user