Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8a0613b

Browse files
committed
Add solution #3046
1 parent 98717e6 commit 8a0613b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,6 +2148,7 @@
21482148
3042|[Count Prefix and Suffix Pairs I](./solutions/3042-count-prefix-and-suffix-pairs-i.js)|Easy|
21492149
3043|[Find the Length of the Longest Common Prefix](./solutions/3043-find-the-length-of-the-longest-common-prefix.js)|Medium|
21502150
3044|[Most Frequent Prime](./solutions/3044-most-frequent-prime.js)|Medium|
2151+
3046|[Split the Array](./solutions/3046-split-the-array.js)|Easy|
21512152
3066|[Minimum Operations to Exceed Threshold Value II](./solutions/3066-minimum-operations-to-exceed-threshold-value-ii.js)|Medium|
21522153
3068|[Find the Maximum Sum of Node Values](./solutions/3068-find-the-maximum-sum-of-node-values.js)|Hard|
21532154
3105|[Longest Strictly Increasing or Strictly Decreasing Subarray](./solutions/3105-longest-strictly-increasing-or-strictly-decreasing-subarray.js)|Easy|

solutions/3046-split-the-array.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* 3046. Split the Array
3+
* https://leetcode.com/problems/split-the-array/
4+
* Difficulty: Easy
5+
*
6+
* You are given an integer array nums of even length. You have to split the array into two
7+
* parts nums1 and nums2 such that:
8+
* - nums1.length == nums2.length == nums.length / 2.
9+
* - nums1 should contain distinct elements.
10+
* - nums2 should also contain distinct elements.
11+
*
12+
* Return true if it is possible to split the array, and false otherwise.
13+
*/
14+
15+
/**
16+
* @param {number[]} nums
17+
* @return {boolean}
18+
*/
19+
var isPossibleToSplit = function(nums) {
20+
const map = new Map();
21+
22+
for (const num of nums) {
23+
map.set(num, (map.get(num) || 0) + 1);
24+
if (map.get(num) > 2) return false;
25+
}
26+
27+
return true;
28+
};

0 commit comments

Comments
 (0)