1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 10:38:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
程序员小墨 2023-09-01 19:42:45 +08:00
parent 3a7fe98f11
commit 9eb643f137
28 changed files with 16946 additions and 13994 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,70 @@
{
"data": {
"question": {
"questionId": "3097",
"questionFrontendId": "2837",
"categoryTitle": "Database",
"boundTopicId": 2415741,
"title": "Total Traveled Distance",
"titleSlug": "total-traveled-distance",
"content": null,
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Easy",
"likes": 0,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": null,
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": "数据库",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"32\", \"totalSubmission\": \"42\", \"totalAcceptedRaw\": 32, \"totalSubmissionRaw\": 42, \"acRate\": \"76.2%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Users\":[\"user_id\",\"name\"],\"Rides\":[\"ride_id\",\"user_id\",\"distance\"]},\"rows\":{\"Users\":[[17,\"Addison\"],[14,\"Ethan\"],[4,\"Michael\"],[2,\"Avery\"],[10,\"Eleanor\"]],\"Rides\":[[72,17,160],[42,14,161],[45,4,59],[32,2,197],[15,4,357],[56,2,196],[10,14,25]]}}",
"metaData": "{\"mysql\":[\"Create table if not exists Users(user_id int, name varchar(30))\",\"Create table if not exists Rides(ride_id int,user_id int, distance int)\"],\"mssql\":[\"Create table Users(user_id int, name varchar(30))\",\"Create table Rides(ride_id int,user_id int, distance int)\"],\"oraclesql\":[\"Create table Users(user_id int, name varchar(30))\",\"Create table Rides(ride_id int,user_id int, distance int)\"],\"database\":true,\"name\":\"get_total_distance\",\"pythondata\":[\"Users = pd.DataFrame([], columns=['user_id', 'name']).astype({'user_id':'Int64', 'name':'object'})\",\"Rides = pd.DataFrame([], columns=['ride_id', 'user_id', 'distance']).astype({'ride_id':'Int64', 'user_id':'Int64', 'distance':'Int64'})\"],\"database_schema\":{\"Users\":{\"user_id\":\"INT\",\"name\":\"VARCHAR(30)\"},\"Rides\":{\"ride_id\":\"INT\",\"user_id\":\"INT\",\"distance\":\"INT\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table if not exists Users(user_id int, name varchar(30))",
"Create table if not exists Rides(ride_id int,user_id int, distance int)",
"Truncate table Users",
"insert into Users (user_id, name) values ('17', 'Addison')",
"insert into Users (user_id, name) values ('14', 'Ethan')",
"insert into Users (user_id, name) values ('4', 'Michael')",
"insert into Users (user_id, name) values ('2', 'Avery')",
"insert into Users (user_id, name) values ('10', 'Eleanor')",
"Truncate table Rides",
"insert into Rides (ride_id, user_id, distance) values ('72', '17', '160')",
"insert into Rides (ride_id, user_id, distance) values ('42', '14', '161')",
"insert into Rides (ride_id, user_id, distance) values ('45', '4', '59')",
"insert into Rides (ride_id, user_id, distance) values ('32', '2', '197')",
"insert into Rides (ride_id, user_id, distance) values ('15', '4', '357')",
"insert into Rides (ride_id, user_id, distance) values ('56', '2', '196')",
"insert into Rides (ride_id, user_id, distance) values ('10', '14', '25')"
],
"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>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"Users\":[\"user_id\",\"name\"],\"Rides\":[\"ride_id\",\"user_id\",\"distance\"]},\"rows\":{\"Users\":[[17,\"Addison\"],[14,\"Ethan\"],[4,\"Michael\"],[2,\"Avery\"],[10,\"Eleanor\"]],\"Rides\":[[72,17,160],[42,14,161],[45,4,59],[32,2,197],[15,4,357],[56,2,196],[10,14,25]]}}",
"__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

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,54 @@
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的数组&nbsp;<code>nums</code>&nbsp;,它包含 <strong>非负</strong>&nbsp;整数,且全部为 <code>2</code>&nbsp;的幂,同时给你一个整数&nbsp;<code>target</code>&nbsp;</p>
<p>一次操作中,你必须对数组做以下修改:</p>
<ul>
<li>选择数组中一个元素&nbsp;<code>nums[i]</code>&nbsp;,满足&nbsp;<code>nums[i] &gt; 1</code>&nbsp;</li>
<li>&nbsp;<code>nums[i]</code>&nbsp;从数组中删除。</li>
<li><code>nums</code>&nbsp;<strong>末尾</strong>&nbsp;添加 <strong>两个</strong>&nbsp;数,值都为&nbsp;<code>nums[i] / 2</code>&nbsp;</li>
</ul>
<p>你的目标是让 <code>nums</code>&nbsp;的一个 <strong>子序列</strong>&nbsp;的元素和等于&nbsp;<code>target</code>&nbsp;,请你返回达成这一目标的 <strong>最少操作次数</strong>&nbsp;。如果无法得到这样的子序列,请你返回 <code>-1</code>&nbsp;</p>
<p>数组中一个 <strong>子序列</strong>&nbsp;是通过删除原数组中一些元素,并且不改变剩余元素顺序得到的剩余数组。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<b>输入:</b>nums = [1,2,8], target = 7
<b>输出:</b>1
<b>解释:</b>第一次操作中,我们选择元素 nums[2] 。数组变为 nums = [1,2,4,4] 。
这时候nums 包含子序列 [1,2,4] ,和为 7 。
无法通过更少的操作得到和为 7 的子序列。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>nums = [1,32,1,2], target = 12
<b>输出:</b>2
<b>解释:</b>第一次操作中,我们选择元素 nums[1] 。数组变为 nums = [1,1,2,16,16] 。
第二次操作中,我们选择元素 nums[3] 。数组变为 nums = [1,1,2,16,8,8] 。
这时候nums 包含子序列 [1,1,2,8] ,和为 12 。
无法通过更少的操作得到和为 12 的子序列。</pre>
<p><strong class="example">示例 3</strong></p>
<pre>
<b>输入:</b>nums = [1,32,1], target = 35
<b>输出:</b>-1
<b>解释:</b>无法得到和为 35 的子序列。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
<li><code>1 &lt;= nums[i] &lt;= 2<sup>30</sup></code></li>
<li><code>nums</code>&nbsp;只包含非负整数,且均为 2 的幂。</li>
<li><code>1 &lt;= target &lt; 2<sup>31</sup></code></li>
</ul>

View File

@ -0,0 +1,127 @@
<p>给你一个长度为 <code>n</code>&nbsp;下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>receiver</code>&nbsp;和一个整数&nbsp;<code>k</code>&nbsp;</p>
<p>总共有&nbsp;<code>n</code>&nbsp;名玩家,玩家 <strong>编号</strong>&nbsp;互不相同,且为&nbsp;<code>[0, n - 1]</code>&nbsp;中的整数。这些玩家玩一个传球游戏,<code>receiver[i]</code>&nbsp;表示编号为 <code>i</code>&nbsp;的玩家会传球给编号为 <code>receiver[i]</code>&nbsp;的玩家。玩家可以传球给自己,也就是说&nbsp;<code>receiver[i]</code>&nbsp;可能等于&nbsp;<code>i</code>&nbsp;</p>
<p>你需要从 <code>n</code>&nbsp;名玩家中选择一名玩家作为游戏开始时唯一手中有球的玩家,球会被传 <strong>恰好</strong>&nbsp;<code>k</code>&nbsp;次。</p>
<p>如果选择编号为 <code>x</code>&nbsp;的玩家作为开始玩家,定义函数&nbsp;<code>f(x)</code>&nbsp;表示从编号为&nbsp;<code>x</code>&nbsp;的玩家开始,<code>k</code>&nbsp;次传球内所有接触过球玩家的编号之&nbsp;<strong></strong>&nbsp;,如果有玩家多次触球,则 <strong>累加多次</strong>&nbsp;。换句话说,&nbsp;<code>f(x) = x + receiver[x] + receiver[receiver[x]] + ... + receiver<sup>(k)</sup>[x]</code>&nbsp;</p>
<p>你的任务时选择开始玩家 <code>x</code>&nbsp;,目的是<strong>&nbsp;最大化</strong>&nbsp;<code>f(x)</code>&nbsp;</p>
<p>请你返回函数的 <strong>最大值</strong>&nbsp;</p>
<p><strong>注意:</strong><code>receiver</code>&nbsp;可能含有重复元素。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
<tbody>
<tr>
<th style="padding: 5px; border: 1px solid black;">传递次数</th>
<th style="padding: 5px; border: 1px solid black;">传球者编号</th>
<th style="padding: 5px; border: 1px solid black;">接球者编号</th>
<th style="padding: 5px; border: 1px solid black;">x + 所有接球者编号</th>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">3</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">0</td>
<td style="padding: 5px; border: 1px solid black;">3</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">3</td>
<td style="padding: 5px; border: 1px solid black;">0</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">5</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">4</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">6</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<pre>
<b>输入:</b>receiver = [2,0,1], k = 4
<b>输出:</b>6
<b>解释:</b>上表展示了从编号为 x = 2 开始的游戏过程。
从表中可知f(2) 等于 6 。
6 是能得到最大的函数值。
所以输出为 6 。
</pre>
<p><strong class="example">示例 2</strong></p>
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
<tbody>
<tr>
<th style="padding: 5px; border: 1px solid black;">传递次数</th>
<th style="padding: 5px; border: 1px solid black;">传球者编号</th>
<th style="padding: 5px; border: 1px solid black;">接球者编号</th>
<th style="padding: 5px; border: 1px solid black;">x + 所有接球者编号</th>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">4</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">4</td>
<td style="padding: 5px; border: 1px solid black;">3</td>
<td style="padding: 5px; border: 1px solid black;">7</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">3</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">9</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">3</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">10</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<pre>
<b>输入:</b>receiver = [1,1,1,2,3], k = 3
<b>输出:</b>10
<b>解释:</b>上表展示了从编号为 x = 4 开始的游戏过程。
从表中可知f(4) 等于 10 。
10 是能得到最大的函数值。
所以输出为 10 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= receiver.length == n &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= receiver[i] &lt;= n - 1</code></li>
<li><code>1 &lt;= k &lt;= 10<sup>10</sup></code></li>
</ul>

View File

@ -0,0 +1,53 @@
<p>给你两个正整数:<code>n</code><code>target</code></p>
<p>如果数组 <code>nums</code> 满足下述条件,则称其为 <strong>美丽数组</strong></p>
<ul>
<li><code>nums.length == n</code>.</li>
<li><code>nums</code> 由两两互不相同的正整数组成。</li>
<li>在范围 <code>[0, n-1]</code> 内,<strong>不存在 </strong>两个 <strong>不同</strong> 下标 <code>i</code><code>j</code> ,使得 <code>nums[i] + nums[j] == target</code></li>
</ul>
<p>返回符合条件的美丽数组所可能具备的 <strong>最小</strong> 和。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>n = 2, target = 3
<strong>输出:</strong>4
<strong>解释:</strong>nums = [1,3] 是美丽数组。
- nums 的长度为 n = 2 。
- nums 由两两互不相同的正整数组成。
- 不存在两个不同下标 i 和 j ,使得 nums[i] + nums[j] == 3 。
可以证明 4 是符合条件的美丽数组所可能具备的最小和。</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>n = 3, target = 3
<strong>输出:</strong>8
<strong>解释:</strong>
nums = [1,3,4] 是美丽数组。
- nums 的长度为 n = 3 。
- nums 由两两互不相同的正整数组成。
- 不存在两个不同下标 i 和 j ,使得 nums[i] + nums[j] == 3 。
可以证明 8 是符合条件的美丽数组所可能具备的最小和。</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>n = 1, target = 1
<strong>输出:</strong>1
<strong>解释:</strong>nums = [1] 是美丽数组。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= target &lt;= 10<sup>5</sup></code></li>
</ul>

View File

@ -0,0 +1,45 @@
<p>给你一个长度为 <code>n</code> 的字符串 <code>moves</code> ,该字符串仅由字符 <code>'L'</code><code>'R'</code><code>'_'</code> 组成。字符串表示你在一条原点为 <code>0</code> 的数轴上的若干次移动。</p>
<p>你的初始位置就在原点(<code>0</code>),第 <code>i</code> 次移动过程中,你可以根据对应字符选择移动方向:</p>
<ul>
<li>如果 <code>moves[i] = 'L'</code><code>moves[i] = '_'</code> ,可以选择向左移动一个单位距离</li>
<li>如果 <code>moves[i] = 'R'</code><code>moves[i] = '_'</code> ,可以选择向右移动一个单位距离</li>
</ul>
<p>移动 <code>n</code> 次之后,请你找出可以到达的距离原点 <strong>最远</strong> 的点,并返回 <strong>从原点到这一点的距离</strong></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>moves = "L_RL__R"
<strong>输出:</strong>3
<strong>解释:</strong>可以到达的距离原点 0 最远的点是 -3 ,移动的序列为 "LLRLLLR" 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>moves = "_R__LL_"
<strong>输出:</strong>5
<strong>解释:</strong>可以到达的距离原点 0 最远的点是 -5 ,移动的序列为 "LRLLLLL" 。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>moves = "_______"
<strong>输出:</strong>7
<strong>解释:</strong>可以到达的距离原点 0 最远的点是 7 ,移动的序列为 "RRRRRRR" 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= moves.length == n &lt;= 50</code></li>
<li><code>moves</code> 仅由字符 <code>'L'</code><code>'R'</code><code>'_'</code> 组成</li>
</ul>

View File

@ -0,0 +1,52 @@
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of <strong>non-negative</strong> powers of <code>2</code>, and an integer <code>target</code>.</p>
<p>In one operation, you must apply the following changes to the array:</p>
<ul>
<li>Choose any element of the array <code>nums[i]</code> such that <code>nums[i] &gt; 1</code>.</li>
<li>Remove <code>nums[i]</code> from the array.</li>
<li>Add <strong>two</strong> occurrences of <code>nums[i] / 2</code> to the <strong>end</strong> of <code>nums</code>.</li>
</ul>
<p>Return the <em><strong>minimum number of operations</strong> you need to perform so that </em><code>nums</code><em> contains a <strong>subsequence</strong> whose elements sum to</em> <code>target</code>. If it is impossible to obtain such a subsequence, return <code>-1</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>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,2,8], target = 7
<strong>Output:</strong> 1
<strong>Explanation:</strong> In the first operation, we choose element nums[2]. The array becomes equal to nums = [1,2,4,4].
At this stage, nums contains the subsequence [1,2,4] which sums up to 7.
It can be shown that there is no shorter sequence of operations that results in a subsequnce that sums up to 7.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,32,1,2], target = 12
<strong>Output:</strong> 2
<strong>Explanation:</strong> In the first operation, we choose element nums[1]. The array becomes equal to nums = [1,1,2,16,16].
In the second operation, we choose element nums[3]. The array becomes equal to nums = [1,1,2,16,8,8]
At this stage, nums contains the subsequence [1,1,2,8] which sums up to 12.
It can be shown that there is no shorter sequence of operations that results in a subsequence that sums up to 12.</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,32,1], target = 35
<strong>Output:</strong> -1
<strong>Explanation:</strong> It can be shown that no sequence of operations results in a subsequence that sums up to 35.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
<li><code>1 &lt;= nums[i] &lt;= 2<sup>30</sup></code></li>
<li><code>nums</code> consists only of non-negative powers of two.</li>
<li><code>1 &lt;= target &lt; 2<sup>31</sup></code></li>
</ul>

View File

@ -0,0 +1,121 @@
<p>You are given a <strong>0-indexed</strong> integer array <code>receiver</code> of length <code>n</code> and an integer <code>k</code>.</p>
<p>There are <code>n</code> players having a <strong>unique id</strong> in the range <code>[0, n - 1]</code> who will play a ball passing game, and <code>receiver[i]</code> is the id of the player who receives passes from the player with id <code>i</code>. Players can pass to themselves, <strong>i.e.</strong> <code>receiver[i]</code> may be equal to <code>i</code>.</p>
<p>You must choose one of the <code>n</code> players as the starting player for the game, and the ball will be passed <strong>exactly</strong> <code>k</code> times starting from the chosen player.</p>
<p>For a chosen starting player having id <code>x</code>, we define a function <code>f(x)</code> that denotes the <strong>sum</strong> of <code>x</code> and the <strong>ids</strong> of all players who receive the ball during the <code>k</code> passes, <strong>including repetitions</strong>. In other words, <code>f(x) = x + receiver[x] + receiver[receiver[x]] + ... + receiver<sup>(k)</sup>[x]</code>.</p>
<p>Your task is to choose a starting player having id <code>x</code> that <strong>maximizes</strong> the value of <code>f(x)</code>.</p>
<p>Return <em>an integer denoting the <strong>maximum</strong> value of the function.</em></p>
<p><strong>Note:</strong> <code>receiver</code> may contain duplicates.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
<tbody>
<tr>
<th style="padding: 5px; border: 1px solid black;">Pass Number</th>
<th style="padding: 5px; border: 1px solid black;">Sender ID</th>
<th style="padding: 5px; border: 1px solid black;">Receiver ID</th>
<th style="padding: 5px; border: 1px solid black;">x + Receiver IDs</th>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">3</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">0</td>
<td style="padding: 5px; border: 1px solid black;">3</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">3</td>
<td style="padding: 5px; border: 1px solid black;">0</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">5</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">4</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">6</td>
</tr>
</tbody>
</table>
<pre>
<strong>Input:</strong> receiver = [2,0,1], k = 4
<strong>Output:</strong> 6
<strong>Explanation:</strong> The table above shows a simulation of the game starting with the player having id x = 2.
From the table, f(2) is equal to 6.
It can be shown that 6 is the maximum achievable value of the function.
Hence, the output is 6.
</pre>
<p><strong class="example">Example 2:</strong></p>
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
<tbody>
<tr>
<th style="padding: 5px; border: 1px solid black;">Pass Number</th>
<th style="padding: 5px; border: 1px solid black;">Sender ID</th>
<th style="padding: 5px; border: 1px solid black;">Receiver ID</th>
<th style="padding: 5px; border: 1px solid black;">x + Receiver IDs</th>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">4</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">4</td>
<td style="padding: 5px; border: 1px solid black;">3</td>
<td style="padding: 5px; border: 1px solid black;">7</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">3</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">9</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">3</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">10</td>
</tr>
</tbody>
</table>
<pre>
<strong>Input:</strong> receiver = [1,1,1,2,3], k = 3
<strong>Output:</strong> 10
<strong>Explanation:</strong> The table above shows a simulation of the game starting with the player having id x = 4.
From the table, f(4) is equal to 10.
It can be shown that 10 is the maximum achievable value of the function.
Hence, the output is 10.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= receiver.length == n &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= receiver[i] &lt;= n - 1</code></li>
<li><code>1 &lt;= k &lt;= 10<sup>10</sup></code></li>
</ul>

View File

@ -0,0 +1,52 @@
<p>You are given positive integers <code>n</code> and <code>target</code>.</p>
<p>An array <code>nums</code> is <strong>beautiful</strong> if it meets the following conditions:</p>
<ul>
<li><code>nums.length == n</code>.</li>
<li><code>nums</code> consists of pairwise <strong>distinct</strong> <strong>positive</strong> integers.</li>
<li>There doesn&#39;t exist two <strong>distinct</strong> indices, <code>i</code> and <code>j</code>, in the range <code>[0, n - 1]</code>, such that <code>nums[i] + nums[j] == target</code>.</li>
</ul>
<p>Return <em>the <strong>minimum</strong> possible sum that a beautiful array could have</em>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> n = 2, target = 3
<strong>Output:</strong> 4
<strong>Explanation:</strong> We can see that nums = [1,3] is beautiful.
- The array nums has length n = 2.
- The array nums consists of pairwise distinct positive integers.
- There doesn&#39;t exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
It can be proven that 4 is the minimum possible sum that a beautiful array could have.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> n = 3, target = 3
<strong>Output:</strong> 8
<strong>Explanation:</strong> We can see that nums = [1,3,4] is beautiful.
- The array nums has length n = 3.
- The array nums consists of pairwise distinct positive integers.
- There doesn&#39;t exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
It can be proven that 8 is the minimum possible sum that a beautiful array could have.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> n = 1, target = 1
<strong>Output:</strong> 1
<strong>Explanation:</strong> We can see, that nums = [1] is beautiful.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= target &lt;= 10<sup>5</sup></code></li>
</ul>

View File

@ -0,0 +1,43 @@
<p>You are given a string <code>moves</code> of length <code>n</code> consisting only of characters <code>&#39;L&#39;</code>, <code>&#39;R&#39;</code>, and <code>&#39;_&#39;</code>. The string represents your movement on a number line starting from the origin <code>0</code>.</p>
<p>In the <code>i<sup>th</sup></code> move, you can choose one of the following directions:</p>
<ul>
<li>move to the left if <code>moves[i] = &#39;L&#39;</code> or <code>moves[i] = &#39;_&#39;</code></li>
<li>move to the right if <code>moves[i] = &#39;R&#39;</code> or <code>moves[i] = &#39;_&#39;</code></li>
</ul>
<p>Return <em>the <strong>distance from the origin</strong> of the <strong>furthest</strong> point you can get to after </em><code>n</code><em> moves</em>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> moves = &quot;L_RL__R&quot;
<strong>Output:</strong> 3
<strong>Explanation:</strong> The furthest point we can reach from the origin 0 is point -3 through the following sequence of moves &quot;LLRLLLR&quot;.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> moves = &quot;_R__LL_&quot;
<strong>Output:</strong> 5
<strong>Explanation:</strong> The furthest point we can reach from the origin 0 is point -5 through the following sequence of moves &quot;LRLLLLL&quot;.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> moves = &quot;_______&quot;
<strong>Output:</strong> 7
<strong>Explanation:</strong> The furthest point we can reach from the origin 0 is point 7 through the following sequence of moves &quot;RRRRRRR&quot;.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= moves.length == n &lt;= 50</code></li>
<li><code>moves</code> consists only of characters <code>&#39;L&#39;</code>, <code>&#39;R&#39;</code> and <code>&#39;_&#39;</code>.</li>
</ul>

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,67 @@
{
"data": {
"question": {
"questionId": "3097",
"questionFrontendId": "2837",
"boundTopicId": null,
"title": "Total Traveled Distance",
"titleSlug": "total-traveled-distance",
"content": null,
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Easy",
"likes": 6,
"dislikes": 2,
"isLiked": null,
"similarQuestions": "[]",
"exampleTestcases": "{\"headers\":{\"Users\":[\"user_id\",\"name\"],\"Rides\":[\"ride_id\",\"user_id\",\"distance\"]},\"rows\":{\"Users\":[[17,\"Addison\"],[14,\"Ethan\"],[4,\"Michael\"],[2,\"Avery\"],[10,\"Eleanor\"]],\"Rides\":[[72,17,160],[42,14,161],[45,4,59],[32,2,197],[15,4,357],[56,2,196],[10,14,25]]}}",
"categoryTitle": "Database",
"contributors": [],
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"215\", \"totalSubmission\": \"270\", \"totalAcceptedRaw\": 215, \"totalSubmissionRaw\": 270, \"acRate\": \"79.6%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Users\":[\"user_id\",\"name\"],\"Rides\":[\"ride_id\",\"user_id\",\"distance\"]},\"rows\":{\"Users\":[[17,\"Addison\"],[14,\"Ethan\"],[4,\"Michael\"],[2,\"Avery\"],[10,\"Eleanor\"]],\"Rides\":[[72,17,160],[42,14,161],[45,4,59],[32,2,197],[15,4,357],[56,2,196],[10,14,25]]}}",
"metaData": "{\"mysql\": [\"Create table if not exists Users(user_id int, name varchar(30))\", \"Create table if not exists Rides(ride_id int,user_id int, distance int)\"], \"mssql\": [\"Create table Users(user_id int, name varchar(30))\", \"Create table Rides(ride_id int,user_id int, distance int)\"], \"oraclesql\": [\"Create table Users(user_id int, name varchar(30))\", \"Create table Rides(ride_id int,user_id int, distance int)\"], \"database\": true, \"name\": \"get_total_distance\", \"pythondata\": [\"Users = pd.DataFrame([], columns=['user_id', 'name']).astype({'user_id':'Int64', 'name':'object'})\", \"Rides = pd.DataFrame([], columns=['ride_id', 'user_id', 'distance']).astype({'ride_id':'Int64', 'user_id':'Int64', 'distance':'Int64'})\"], \"database_schema\": {\"Users\": {\"user_id\": \"INT\", \"name\": \"VARCHAR(30)\"}, \"Rides\": {\"ride_id\": \"INT\", \"user_id\": \"INT\", \"distance\": \"INT\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table if not exists Users(user_id int, name varchar(30))",
"Create table if not exists Rides(ride_id int,user_id int, distance int)",
"Truncate table Users",
"insert into Users (user_id, name) values ('17', 'Addison')",
"insert into Users (user_id, name) values ('14', 'Ethan')",
"insert into Users (user_id, name) values ('4', 'Michael')",
"insert into Users (user_id, name) values ('2', 'Avery')",
"insert into Users (user_id, name) values ('10', 'Eleanor')",
"Truncate table Rides",
"insert into Rides (ride_id, user_id, distance) values ('72', '17', '160')",
"insert into Rides (ride_id, user_id, distance) values ('42', '14', '161')",
"insert into Rides (ride_id, user_id, distance) values ('45', '4', '59')",
"insert into Rides (ride_id, user_id, distance) values ('32', '2', '197')",
"insert into Rides (ride_id, user_id, distance) values ('15', '4', '357')",
"insert into Rides (ride_id, user_id, distance) values ('56', '2', '196')",
"insert into Rides (ride_id, user_id, distance) values ('10', '14', '25')"
],
"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>\"]}",
"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

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,52 @@
<p>You are given positive integers <code>n</code> and <code>target</code>.</p>
<p>An array <code>nums</code> is <strong>beautiful</strong> if it meets the following conditions:</p>
<ul>
<li><code>nums.length == n</code>.</li>
<li><code>nums</code> consists of pairwise <strong>distinct</strong> <strong>positive</strong> integers.</li>
<li>There doesn&#39;t exist two <strong>distinct</strong> indices, <code>i</code> and <code>j</code>, in the range <code>[0, n - 1]</code>, such that <code>nums[i] + nums[j] == target</code>.</li>
</ul>
<p>Return <em>the <strong>minimum</strong> possible sum that a beautiful array could have</em>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> n = 2, target = 3
<strong>Output:</strong> 4
<strong>Explanation:</strong> We can see that nums = [1,3] is beautiful.
- The array nums has length n = 2.
- The array nums consists of pairwise distinct positive integers.
- There doesn&#39;t exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
It can be proven that 4 is the minimum possible sum that a beautiful array could have.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> n = 3, target = 3
<strong>Output:</strong> 8
<strong>Explanation:</strong> We can see that nums = [1,3,4] is beautiful.
- The array nums has length n = 3.
- The array nums consists of pairwise distinct positive integers.
- There doesn&#39;t exist two distinct indices, i and j, with nums[i] + nums[j] == 3.
It can be proven that 8 is the minimum possible sum that a beautiful array could have.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> n = 1, target = 1
<strong>Output:</strong> 1
<strong>Explanation:</strong> We can see, that nums = [1] is beautiful.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= target &lt;= 10<sup>5</sup></code></li>
</ul>

View File

@ -0,0 +1,43 @@
<p>You are given a string <code>moves</code> of length <code>n</code> consisting only of characters <code>&#39;L&#39;</code>, <code>&#39;R&#39;</code>, and <code>&#39;_&#39;</code>. The string represents your movement on a number line starting from the origin <code>0</code>.</p>
<p>In the <code>i<sup>th</sup></code> move, you can choose one of the following directions:</p>
<ul>
<li>move to the left if <code>moves[i] = &#39;L&#39;</code> or <code>moves[i] = &#39;_&#39;</code></li>
<li>move to the right if <code>moves[i] = &#39;R&#39;</code> or <code>moves[i] = &#39;_&#39;</code></li>
</ul>
<p>Return <em>the <strong>distance from the origin</strong> of the <strong>furthest</strong> point you can get to after </em><code>n</code><em> moves</em>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> moves = &quot;L_RL__R&quot;
<strong>Output:</strong> 3
<strong>Explanation:</strong> The furthest point we can reach from the origin 0 is point -3 through the following sequence of moves &quot;LLRLLLR&quot;.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> moves = &quot;_R__LL_&quot;
<strong>Output:</strong> 5
<strong>Explanation:</strong> The furthest point we can reach from the origin 0 is point -5 through the following sequence of moves &quot;LRLLLLL&quot;.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> moves = &quot;_______&quot;
<strong>Output:</strong> 7
<strong>Explanation:</strong> The furthest point we can reach from the origin 0 is point 7 through the following sequence of moves &quot;RRRRRRR&quot;.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= moves.length == n &lt;= 50</code></li>
<li><code>moves</code> consists only of characters <code>&#39;L&#39;</code>, <code>&#39;R&#39;</code> and <code>&#39;_&#39;</code>.</li>
</ul>

View File

@ -0,0 +1,121 @@
<p>You are given a <strong>0-indexed</strong> integer array <code>receiver</code> of length <code>n</code> and an integer <code>k</code>.</p>
<p>There are <code>n</code> players having a <strong>unique id</strong> in the range <code>[0, n - 1]</code> who will play a ball passing game, and <code>receiver[i]</code> is the id of the player who receives passes from the player with id <code>i</code>. Players can pass to themselves, <strong>i.e.</strong> <code>receiver[i]</code> may be equal to <code>i</code>.</p>
<p>You must choose one of the <code>n</code> players as the starting player for the game, and the ball will be passed <strong>exactly</strong> <code>k</code> times starting from the chosen player.</p>
<p>For a chosen starting player having id <code>x</code>, we define a function <code>f(x)</code> that denotes the <strong>sum</strong> of <code>x</code> and the <strong>ids</strong> of all players who receive the ball during the <code>k</code> passes, <strong>including repetitions</strong>. In other words, <code>f(x) = x + receiver[x] + receiver[receiver[x]] + ... + receiver<sup>(k)</sup>[x]</code>.</p>
<p>Your task is to choose a starting player having id <code>x</code> that <strong>maximizes</strong> the value of <code>f(x)</code>.</p>
<p>Return <em>an integer denoting the <strong>maximum</strong> value of the function.</em></p>
<p><strong>Note:</strong> <code>receiver</code> may contain duplicates.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
<tbody>
<tr>
<th style="padding: 5px; border: 1px solid black;">Pass Number</th>
<th style="padding: 5px; border: 1px solid black;">Sender ID</th>
<th style="padding: 5px; border: 1px solid black;">Receiver ID</th>
<th style="padding: 5px; border: 1px solid black;">x + Receiver IDs</th>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">3</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">0</td>
<td style="padding: 5px; border: 1px solid black;">3</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">3</td>
<td style="padding: 5px; border: 1px solid black;">0</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">5</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">4</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">6</td>
</tr>
</tbody>
</table>
<pre>
<strong>Input:</strong> receiver = [2,0,1], k = 4
<strong>Output:</strong> 6
<strong>Explanation:</strong> The table above shows a simulation of the game starting with the player having id x = 2.
From the table, f(2) is equal to 6.
It can be shown that 6 is the maximum achievable value of the function.
Hence, the output is 6.
</pre>
<p><strong class="example">Example 2:</strong></p>
<table border="1" cellspacing="3" style="border-collapse: separate; text-align: center;">
<tbody>
<tr>
<th style="padding: 5px; border: 1px solid black;">Pass Number</th>
<th style="padding: 5px; border: 1px solid black;">Sender ID</th>
<th style="padding: 5px; border: 1px solid black;">Receiver ID</th>
<th style="padding: 5px; border: 1px solid black;">x + Receiver IDs</th>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">&nbsp;</td>
<td style="padding: 5px; border: 1px solid black;">4</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">4</td>
<td style="padding: 5px; border: 1px solid black;">3</td>
<td style="padding: 5px; border: 1px solid black;">7</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">3</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">9</td>
</tr>
<tr>
<td style="padding: 5px; border: 1px solid black;">3</td>
<td style="padding: 5px; border: 1px solid black;">2</td>
<td style="padding: 5px; border: 1px solid black;">1</td>
<td style="padding: 5px; border: 1px solid black;">10</td>
</tr>
</tbody>
</table>
<pre>
<strong>Input:</strong> receiver = [1,1,1,2,3], k = 3
<strong>Output:</strong> 10
<strong>Explanation:</strong> The table above shows a simulation of the game starting with the player having id x = 4.
From the table, f(4) is equal to 10.
It can be shown that 10 is the maximum achievable value of the function.
Hence, the output is 10.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= receiver.length == n &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= receiver[i] &lt;= n - 1</code></li>
<li><code>1 &lt;= k &lt;= 10<sup>10</sup></code></li>
</ul>

View File

@ -0,0 +1,52 @@
<p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of <strong>non-negative</strong> powers of <code>2</code>, and an integer <code>target</code>.</p>
<p>In one operation, you must apply the following changes to the array:</p>
<ul>
<li>Choose any element of the array <code>nums[i]</code> such that <code>nums[i] &gt; 1</code>.</li>
<li>Remove <code>nums[i]</code> from the array.</li>
<li>Add <strong>two</strong> occurrences of <code>nums[i] / 2</code> to the <strong>end</strong> of <code>nums</code>.</li>
</ul>
<p>Return the <em><strong>minimum number of operations</strong> you need to perform so that </em><code>nums</code><em> contains a <strong>subsequence</strong> whose elements sum to</em> <code>target</code>. If it is impossible to obtain such a subsequence, return <code>-1</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>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,2,8], target = 7
<strong>Output:</strong> 1
<strong>Explanation:</strong> In the first operation, we choose element nums[2]. The array becomes equal to nums = [1,2,4,4].
At this stage, nums contains the subsequence [1,2,4] which sums up to 7.
It can be shown that there is no shorter sequence of operations that results in a subsequnce that sums up to 7.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,32,1,2], target = 12
<strong>Output:</strong> 2
<strong>Explanation:</strong> In the first operation, we choose element nums[1]. The array becomes equal to nums = [1,1,2,16,16].
In the second operation, we choose element nums[3]. The array becomes equal to nums = [1,1,2,16,8,8]
At this stage, nums contains the subsequence [1,1,2,8] which sums up to 12.
It can be shown that there is no shorter sequence of operations that results in a subsequence that sums up to 12.</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,32,1], target = 35
<strong>Output:</strong> -1
<strong>Explanation:</strong> It can be shown that no sequence of operations results in a subsequence that sums up to 35.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
<li><code>1 &lt;= nums[i] &lt;= 2<sup>30</sup></code></li>
<li><code>nums</code> consists only of non-negative powers of two.</li>
<li><code>1 &lt;= target &lt; 2<sup>31</sup></code></li>
</ul>