Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 260d765

Browse files
committed
Added README.md file for Minimum Difference in Sums After Removal of Elements
1 parent a8e30ce commit 260d765

File tree

1 file changed

+51
-0
lines changed
  • 2267-minimum-difference-in-sums-after-removal-of-elements

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<h2><a href="https://leetcode.com/problems/minimum-difference-in-sums-after-removal-of-elements">Minimum Difference in Sums After Removal of Elements</a></h2> <img src='https://img.shields.io/badge/Difficulty-Hard-red' alt='Difficulty: Hard' /><hr><p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> consisting of <code>3 * n</code> elements.</p>
2+
3+
<p>You are allowed to remove any <strong>subsequence</strong> of elements of size <strong>exactly</strong> <code>n</code> from <code>nums</code>. The remaining <code>2 * n</code> elements will be divided into two <strong>equal</strong> parts:</p>
4+
5+
<ul>
6+
<li>The first <code>n</code> elements belonging to the first part and their sum is <code>sum<sub>first</sub></code>.</li>
7+
<li>The next <code>n</code> elements belonging to the second part and their sum is <code>sum<sub>second</sub></code>.</li>
8+
</ul>
9+
10+
<p>The <strong>difference in sums</strong> of the two parts is denoted as <code>sum<sub>first</sub> - sum<sub>second</sub></code>.</p>
11+
12+
<ul>
13+
<li>For example, if <code>sum<sub>first</sub> = 3</code> and <code>sum<sub>second</sub> = 2</code>, their difference is <code>1</code>.</li>
14+
<li>Similarly, if <code>sum<sub>first</sub> = 2</code> and <code>sum<sub>second</sub> = 3</code>, their difference is <code>-1</code>.</li>
15+
</ul>
16+
17+
<p>Return <em>the <strong>minimum difference</strong> possible between the sums of the two parts after the removal of </em><code>n</code><em> elements</em>.</p>
18+
19+
<p>&nbsp;</p>
20+
<p><strong class="example">Example 1:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> nums = [3,1,2]
24+
<strong>Output:</strong> -1
25+
<strong>Explanation:</strong> Here, nums has 3 elements, so n = 1.
26+
Thus we have to remove 1 element from nums and divide the array into two equal parts.
27+
- If we remove nums[0] = 3, the array will be [1,2]. The difference in sums of the two parts will be 1 - 2 = -1.
28+
- If we remove nums[1] = 1, the array will be [3,2]. The difference in sums of the two parts will be 3 - 2 = 1.
29+
- If we remove nums[2] = 2, the array will be [3,1]. The difference in sums of the two parts will be 3 - 1 = 2.
30+
The minimum difference between sums of the two parts is min(-1,1,2) = -1.
31+
</pre>
32+
33+
<p><strong class="example">Example 2:</strong></p>
34+
35+
<pre>
36+
<strong>Input:</strong> nums = [7,9,5,8,1,3]
37+
<strong>Output:</strong> 1
38+
<strong>Explanation:</strong> Here n = 2. So we must remove 2 elements and divide the remaining array into two parts containing two elements each.
39+
If we remove nums[2] = 5 and nums[3] = 8, the resultant array will be [7,9,1,3]. The difference in sums will be (7+9) - (1+3) = 12.
40+
To obtain the minimum difference, we should remove nums[1] = 9 and nums[4] = 1. The resultant array becomes [7,5,8,3]. The difference in sums of the two parts is (7+5) - (8+3) = 1.
41+
It can be shown that it is not possible to obtain a difference smaller than 1.
42+
</pre>
43+
44+
<p>&nbsp;</p>
45+
<p><strong>Constraints:</strong></p>
46+
47+
<ul>
48+
<li><code>nums.length == 3 * n</code></li>
49+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
50+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
51+
</ul>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /