Skip to content

Commit 1acceed

Browse files
committed
2698-FIND-THE-ARRAY-CONCATENATION-VALUE Stats: Time: 0 ms (100%), Space: 17.7 MB (87.92%) - LeetHub
1 parent 8d70a99 commit 1acceed

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def findTheArrayConcVal(self, nums: List[int]) -> int:
3+
i = 0
4+
j = len(nums) - 1
5+
6+
result = 0
7+
while i < j:
8+
result += int(str(nums[i]) + str(nums[j]))
9+
i += 1
10+
j -= 1
11+
12+
if i == j:
13+
result += nums[i]
14+
15+
return result
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<h2><a href="https://leetcode.com/problems/find-the-array-concatenation-value">2698. Find the Array Concatenation Value</a></h2><h3>Easy</h3><hr><p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>.</p>
2+
3+
<p>The <strong>concatenation</strong> of two numbers is the number formed by concatenating their numerals.</p>
4+
5+
<ul>
6+
<li>For example, the concatenation of <code>15</code>, <code>49</code> is <code>1549</code>.</li>
7+
</ul>
8+
9+
<p>The <strong>concatenation value</strong> of <code>nums</code> is initially equal to <code>0</code>. Perform this operation until <code>nums</code> becomes empty:</p>
10+
11+
<ul>
12+
<li>If <code>nums</code> has a size greater than one, add the value of the concatenation of the first and the last element to the <strong>concatenation value</strong> of <code>nums</code>, and remove those two elements from <code>nums</code>. For example, if the <code>nums</code> was <code>[1, 2, 4, 5, 6]</code>, add 16 to the <code>concatenation value</code>.</li>
13+
<li>If only one element exists in <code>nums</code>, add its value to the <strong>concatenation value</strong> of <code>nums</code>, then remove it.</li>
14+
</ul>
15+
16+
<p>Return<em> the concatenation value of <code>nums</code></em>.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong class="example">Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> nums = [7,52,2,4]
23+
<strong>Output:</strong> 596
24+
<strong>Explanation:</strong> Before performing any operation, nums is [7,52,2,4] and concatenation value is 0.
25+
- In the first operation:
26+
We pick the first element, 7, and the last element, 4.
27+
Their concatenation is 74, and we add it to the concatenation value, so it becomes equal to 74.
28+
Then we delete them from nums, so nums becomes equal to [52,2].
29+
- In the second operation:
30+
We pick the first element, 52, and the last element, 2.
31+
Their concatenation is 522, and we add it to the concatenation value, so it becomes equal to 596.
32+
Then we delete them from the nums, so nums becomes empty.
33+
Since the concatenation value is 596 so the answer is 596.
34+
</pre>
35+
36+
<p><strong class="example">Example 2:</strong></p>
37+
38+
<pre>
39+
<strong>Input:</strong> nums = [5,14,13,8,12]
40+
<strong>Output:</strong> 673
41+
<strong>Explanation:</strong> Before performing any operation, nums is [5,14,13,8,12] and concatenation value is 0.
42+
- In the first operation:
43+
We pick the first element, 5, and the last element, 12.
44+
Their concatenation is 512, and we add it to the concatenation value, so it becomes equal to 512.
45+
Then we delete them from the nums, so nums becomes equal to [14,13,8].
46+
- In the second operation:
47+
We pick the first element, 14, and the last element, 8.
48+
Their concatenation is 148, and we add it to the concatenation value, so it becomes equal to 660.
49+
Then we delete them from the nums, so nums becomes equal to [13].
50+
- In the third operation:
51+
nums has only one element, so we pick 13 and add it to the concatenation value, so it becomes equal to 673.
52+
Then we delete it from nums, so nums become empty.
53+
Since the concatenation value is 673 so the answer is 673.
54+
</pre>
55+
56+
<p>&nbsp;</p>
57+
<p><strong>Constraints:</strong></p>
58+
59+
<ul>
60+
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
61+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
62+
</ul>
63+
64+
<p>&nbsp;</p>
65+
<style type="text/css">.spoilerbutton {display:block; border:dashed; padding: 0px 0px; margin:10px 0px; font-size:150%; font-weight: bold; color:#000000; background-color:cyan; outline:0; 
66+
}
67+
.spoiler {overflow:hidden;}
68+
.spoiler > div {-webkit-transition: all 0s ease;-moz-transition: margin 0s ease;-o-transition: all 0s ease;transition: margin 0s ease;}
69+
.spoilerbutton[value="Show Message"] + .spoiler > div {margin-top:-500%;}
70+
.spoilerbutton[value="Hide Message"] + .spoiler {padding:5px;}
71+
</style>

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Collection of LeetCode questions to ace the coding interview! - Created using [L
3030
| [2551-apply-operations-to-an-array](https://github.com/RafaelJohn9/LeetHub/tree/master/2551-apply-operations-to-an-array) |
3131
| [2561-number-of-distinct-averages](https://github.com/RafaelJohn9/LeetHub/tree/master/2561-number-of-distinct-averages) |
3232
| [2634-minimum-common-value](https://github.com/RafaelJohn9/LeetHub/tree/master/2634-minimum-common-value) |
33+
| [2698-find-the-array-concatenation-value](https://github.com/RafaelJohn9/LeetHub/tree/master/2698-find-the-array-concatenation-value) |
3334
| [2816-lexicographically-smallest-palindrome](https://github.com/RafaelJohn9/LeetHub/tree/master/2816-lexicographically-smallest-palindrome) |
3435
| [3471-minimum-average-of-smallest-and-largest-elements](https://github.com/RafaelJohn9/LeetHub/tree/master/3471-minimum-average-of-smallest-and-largest-elements) |
3536
## String
@@ -72,6 +73,7 @@ Collection of LeetCode questions to ace the coding interview! - Created using [L
7273
| [2551-apply-operations-to-an-array](https://github.com/RafaelJohn9/LeetHub/tree/master/2551-apply-operations-to-an-array) |
7374
| [2561-number-of-distinct-averages](https://github.com/RafaelJohn9/LeetHub/tree/master/2561-number-of-distinct-averages) |
7475
| [2634-minimum-common-value](https://github.com/RafaelJohn9/LeetHub/tree/master/2634-minimum-common-value) |
76+
| [2698-find-the-array-concatenation-value](https://github.com/RafaelJohn9/LeetHub/tree/master/2698-find-the-array-concatenation-value) |
7577
| [3471-minimum-average-of-smallest-and-largest-elements](https://github.com/RafaelJohn9/LeetHub/tree/master/3471-minimum-average-of-smallest-and-largest-elements) |
7678
## Bit Manipulation
7779
| |
@@ -87,6 +89,7 @@ Collection of LeetCode questions to ace the coding interview! - Created using [L
8789
| [0861-flipping-an-image](https://github.com/RafaelJohn9/LeetHub/tree/master/0861-flipping-an-image) |
8890
| [0874-backspace-string-compare](https://github.com/RafaelJohn9/LeetHub/tree/master/0874-backspace-string-compare) |
8991
| [2551-apply-operations-to-an-array](https://github.com/RafaelJohn9/LeetHub/tree/master/2551-apply-operations-to-an-array) |
92+
| [2698-find-the-array-concatenation-value](https://github.com/RafaelJohn9/LeetHub/tree/master/2698-find-the-array-concatenation-value) |
9093
## Stack
9194
| |
9295
| ------- |

stats.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"leetcode":{"shas":{"README.md":{"":"aef481a646960280841a1625ca1cac797b3b5d79"},"0680-valid-palindrome-ii":{"sha":"b630fdb718a2206b72caac28716fb430e873d7b8","difficulty":"easy"},"0696-count-binary-substrings":{"sha":"e873cba9e680189fbc0e72309e29a23985e85ba0","difficulty":"easy"},"0841-shortest-distance-to-a-character":{"sha":"9570168273f507ea452025de9722af9b11eb2981","difficulty":"easy"},"0861-flipping-an-image":{"sha":"b5af0d3b7f68c156b26cec64f1431abb8930f658","difficulty":"easy"},"0874-backspace-string-compare":{"sha":"a5a9a358616f36e54ad67219d689c816d0149a67","difficulty":"easy"},"0908-middle-of-the-linked-list":{"sha":"54dc393ab37c8fb16868b082a265ba3e90630e9d","difficulty":"easy"},"0941-sort-array-by-parity":{"sha":"9ba37cf3fe92f32b7b053969a4785d959b1198bc","difficulty":"easy"},"0953-reverse-only-letters":{"sha":"514988ab2aa3e771d1acfbe8e33d98998d063e89","difficulty":"easy"},"0958-sort-array-by-parity-ii":{"sha":"aa2c32c3183addd0664602ca48308af97a619d57","difficulty":"easy"},"0961-long-pressed-name":{"sha":"24707cbcbb2b0a5bd73f7101003d80e08c02674f","difficulty":"easy"},"0979-di-string-match":{"sha":"9234d4dff6a3e7553af9c7f02c7224d2f7562198","difficulty":"easy"},"1019-squares-of-a-sorted-array":{"sha":"4d87415d20e23595be53c0865a150d1dc4e3031c","difficulty":"easy"},"1168-duplicate-zeros":{"sha":"4e9eec927fc8f090db3b7750f1a874273363c476","difficulty":"easy"},"1454-remove-palindromic-subsequences":{"sha":"62b22fda8074dcbf1b2aee55f8ad575b607f2c23","difficulty":"easy"},"1468-check-if-n-and-its-double-exist":{"sha":"194c2c60581667b571931a2c614e9c12df80e8af","difficulty":"easy"},"1486-find-the-distance-value-between-two-arrays":{"sha":"b71ab6c12099400eb73b09f4a2d08d9307db5329","difficulty":"easy"},"2093-check-if-string-is-a-prefix-of-array":{"sha":"f7f4b33ec094f7b8684ec7739079738c326529f9","difficulty":"easy"},"2231-find-first-palindromic-string-in-the-array":{"sha":"5750ecdeccdcf1dd802b7a31bc0ad6a21e041710","difficulty":"easy"},"1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence":{"sha":"b463bfc31d400310e33bce12fddf70849f96ae5d","difficulty":"easy"},"2320-find-all-k-distant-indices-in-an-array":{"sha":"c08fb4bd9cd1288b468f03892eade4ca8a607030","difficulty":"easy"},"2442-number-of-arithmetic-triplets":{"sha":"9740c037b6d6914b11f8041706c8ca0a0ebf1d79","difficulty":"easy"},"2551-apply-operations-to-an-array":{"sha":"7925961f228aeb7fa15535d22bef99b1f18ef4d6","difficulty":"easy"},"2561-number-of-distinct-averages":{"sha":"8d6d54b12fa7873a33a23e543e4f95d7fbf27a0d","difficulty":"easy"},"2816-lexicographically-smallest-palindrome":{"sha":"71646b003b8e3e934f76930f370c52520e9ffab2","difficulty":"easy"},"3471-minimum-average-of-smallest-and-largest-elements":{"sha":"6d9a6822b09bebbc5e019484e7f445176c4c6cec","difficulty":"easy"},"2634-minimum-common-value":{"sha":"","difficulty":"easy"}},"solved":26,"easy":26,"medium":0,"hard":0}}
1+
{"leetcode":{"shas":{"README.md":{"":"98eb851b59f8802f6f24d8df6ca343f8a9be4f50"},"0680-valid-palindrome-ii":{"sha":"b630fdb718a2206b72caac28716fb430e873d7b8","difficulty":"easy"},"0696-count-binary-substrings":{"sha":"e873cba9e680189fbc0e72309e29a23985e85ba0","difficulty":"easy"},"0841-shortest-distance-to-a-character":{"sha":"9570168273f507ea452025de9722af9b11eb2981","difficulty":"easy"},"0861-flipping-an-image":{"sha":"b5af0d3b7f68c156b26cec64f1431abb8930f658","difficulty":"easy"},"0874-backspace-string-compare":{"sha":"a5a9a358616f36e54ad67219d689c816d0149a67","difficulty":"easy"},"0908-middle-of-the-linked-list":{"sha":"54dc393ab37c8fb16868b082a265ba3e90630e9d","difficulty":"easy"},"0941-sort-array-by-parity":{"sha":"9ba37cf3fe92f32b7b053969a4785d959b1198bc","difficulty":"easy"},"0953-reverse-only-letters":{"sha":"514988ab2aa3e771d1acfbe8e33d98998d063e89","difficulty":"easy"},"0958-sort-array-by-parity-ii":{"sha":"aa2c32c3183addd0664602ca48308af97a619d57","difficulty":"easy"},"0961-long-pressed-name":{"sha":"24707cbcbb2b0a5bd73f7101003d80e08c02674f","difficulty":"easy"},"0979-di-string-match":{"sha":"9234d4dff6a3e7553af9c7f02c7224d2f7562198","difficulty":"easy"},"1019-squares-of-a-sorted-array":{"sha":"4d87415d20e23595be53c0865a150d1dc4e3031c","difficulty":"easy"},"1168-duplicate-zeros":{"sha":"4e9eec927fc8f090db3b7750f1a874273363c476","difficulty":"easy"},"1454-remove-palindromic-subsequences":{"sha":"62b22fda8074dcbf1b2aee55f8ad575b607f2c23","difficulty":"easy"},"1468-check-if-n-and-its-double-exist":{"sha":"194c2c60581667b571931a2c614e9c12df80e8af","difficulty":"easy"},"1486-find-the-distance-value-between-two-arrays":{"sha":"b71ab6c12099400eb73b09f4a2d08d9307db5329","difficulty":"easy"},"2093-check-if-string-is-a-prefix-of-array":{"sha":"f7f4b33ec094f7b8684ec7739079738c326529f9","difficulty":"easy"},"2231-find-first-palindromic-string-in-the-array":{"sha":"5750ecdeccdcf1dd802b7a31bc0ad6a21e041710","difficulty":"easy"},"1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence":{"sha":"b463bfc31d400310e33bce12fddf70849f96ae5d","difficulty":"easy"},"2320-find-all-k-distant-indices-in-an-array":{"sha":"c08fb4bd9cd1288b468f03892eade4ca8a607030","difficulty":"easy"},"2442-number-of-arithmetic-triplets":{"sha":"9740c037b6d6914b11f8041706c8ca0a0ebf1d79","difficulty":"easy"},"2551-apply-operations-to-an-array":{"sha":"7925961f228aeb7fa15535d22bef99b1f18ef4d6","difficulty":"easy"},"2561-number-of-distinct-averages":{"sha":"8d6d54b12fa7873a33a23e543e4f95d7fbf27a0d","difficulty":"easy"},"2816-lexicographically-smallest-palindrome":{"sha":"71646b003b8e3e934f76930f370c52520e9ffab2","difficulty":"easy"},"3471-minimum-average-of-smallest-and-largest-elements":{"sha":"6d9a6822b09bebbc5e019484e7f445176c4c6cec","difficulty":"easy"},"2634-minimum-common-value":{"sha":"8d70a991ef4ac04d3d48169be7c89efd5240263e","difficulty":"easy"},"2698-find-the-array-concatenation-value":{"sha":"","difficulty":"easy"}},"solved":27,"easy":27,"medium":0,"hard":0}}

0 commit comments

Comments
 (0)