File tree Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,352 LeetCode solutions in JavaScript
1
+ # 1,353 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1174
1174
1534|[ Count Good Triplets] ( ./solutions/1534-count-good-triplets.js ) |Easy|
1175
1175
1535|[ Find the Winner of an Array Game] ( ./solutions/1535-find-the-winner-of-an-array-game.js ) |Medium|
1176
1176
1536|[ Minimum Swaps to Arrange a Binary Grid] ( ./solutions/1536-minimum-swaps-to-arrange-a-binary-grid.js ) |Medium|
1177
+ 1537|[ Get the Maximum Score] ( ./solutions/1537-get-the-maximum-score.js ) |Hard|
1177
1178
1550|[ Three Consecutive Odds] ( ./solutions/1550-three-consecutive-odds.js ) |Easy|
1178
1179
1551|[ Minimum Operations to Make Array Equal] ( ./solutions/1551-minimum-operations-to-make-array-equal.js ) |Medium|
1179
1180
1566|[ Detect Pattern of Length M Repeated K or More Times] ( ./solutions/1566-detect-pattern-of-length-m-repeated-k-or-more-times.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1537. Get the Maximum Score
3
+ * https://leetcode.com/problems/get-the-maximum-score/
4
+ * Difficulty: Hard
5
+ *
6
+ * You are given two sorted arrays of distinct integers nums1 and nums2.
7
+ *
8
+ * A valid path is defined as follows:
9
+ * - Choose array nums1 or nums2 to traverse (from index-0).
10
+ * - Traverse the current array from left to right.
11
+ * - If you are reading any value that is present in nums1 and nums2 you are allowed to change
12
+ * your path to the other array. (Only one repeated value is considered in the valid path).
13
+ *
14
+ * The score is defined as the sum of unique values in a valid path.
15
+ *
16
+ * Return the maximum score you can obtain of all possible valid paths. Since the answer may be
17
+ * too large, return it modulo 109 + 7.
18
+ */
19
+
20
+ /**
21
+ * @param {number[] } nums1
22
+ * @param {number[] } nums2
23
+ * @return {number }
24
+ */
25
+ var maxSum = function ( nums1 , nums2 ) {
26
+ const MOD = 1e9 + 7 ;
27
+ const m = nums1 . length ;
28
+ const n = nums2 . length ;
29
+ let i = 0 ;
30
+ let j = 0 ;
31
+ let sum1 = 0 ;
32
+ let sum2 = 0 ;
33
+
34
+ while ( i < m && j < n ) {
35
+ if ( nums1 [ i ] < nums2 [ j ] ) {
36
+ sum1 += nums1 [ i ++ ] ;
37
+ } else if ( nums1 [ i ] > nums2 [ j ] ) {
38
+ sum2 += nums2 [ j ++ ] ;
39
+ } else {
40
+ sum1 = sum2 = Math . max ( sum1 , sum2 ) + nums1 [ i ] ;
41
+ i ++ ;
42
+ j ++ ;
43
+ }
44
+ }
45
+
46
+ while ( i < m ) {
47
+ sum1 += nums1 [ i ++ ] ;
48
+ }
49
+
50
+ while ( j < n ) {
51
+ sum2 += nums2 [ j ++ ] ;
52
+ }
53
+
54
+ return Math . max ( sum1 , sum2 ) % MOD ;
55
+ } ;
You can’t perform that action at this time.
0 commit comments