File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 2148
2148
3042|[ Count Prefix and Suffix Pairs I] ( ./solutions/3042-count-prefix-and-suffix-pairs-i.js ) |Easy|
2149
2149
3043|[ Find the Length of the Longest Common Prefix] ( ./solutions/3043-find-the-length-of-the-longest-common-prefix.js ) |Medium|
2150
2150
3044|[ Most Frequent Prime] ( ./solutions/3044-most-frequent-prime.js ) |Medium|
2151
+ 3046|[ Split the Array] ( ./solutions/3046-split-the-array.js ) |Easy|
2151
2152
3066|[ Minimum Operations to Exceed Threshold Value II] ( ./solutions/3066-minimum-operations-to-exceed-threshold-value-ii.js ) |Medium|
2152
2153
3068|[ Find the Maximum Sum of Node Values] ( ./solutions/3068-find-the-maximum-sum-of-node-values.js ) |Hard|
2153
2154
3105|[ Longest Strictly Increasing or Strictly Decreasing Subarray] ( ./solutions/3105-longest-strictly-increasing-or-strictly-decreasing-subarray.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments