Skip to content

Commit 2ee9204

Browse files
alexpantyukhinPanquesito7tjgurwara99
authored
feat: add Maximum Erasure Value LeetCode problem (#1137)
* add leetcode Maximum Erasure Value * Update 1695.c add new line at the end * Rename README.md to DIRECTORY.md * chore: apply suggestions from code review * Update DIRECTORY.md * Update leetcode/DIRECTORY.md Co-authored-by: Taj <[email protected]> Co-authored-by: David Leal <[email protected]> Co-authored-by: Taj <[email protected]>
1 parent b37bf7f commit 2ee9204

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

leetcode/DIRECTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
| 1184 | [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops/) | [C](./src/1184.c) | Easy |
102102
| 1189 | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons/) | [C](./src/1189.c) | Easy |
103103
| 1207 | [Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences/) | [C](./src/1207.c) | Easy |
104+
| 1695 | [Maximum Erasure Value](https://leetcode.com/problems/maximum-erasure-value/) | [C](./src/1695.c) | Medium |
104105
| 1769 | [Minimum Number of Operations to Move All Balls to Each Box](https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box/) | [C](./src/1769.c) | Medium |
105106
| 1524 | [Number of Sub-arrays With Odd Sum](https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum/) | [C](./src/1524.c) | Medium |
106107
| 1653 | [Minimum Deletions to Make String Balanced](https://leetcode.com/problems/minimum-deletions-to-make-string-balanced/) | [C](./src/1653.c) | Medium |

leetcode/src/1695.c

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Window sliding. Runtime: O(n), Space: O(n)
2+
int maximumUniqueSubarray(int* nums, int numsSize){
3+
short* numsSet = (short*)calloc(10001, sizeof(short));
4+
numsSet[nums[0]] = 1;
5+
6+
int maxSum = nums[0];
7+
8+
int windowSumm = maxSum;
9+
int leftIndex = 0;
10+
11+
int num = 0;
12+
for(int i = 1; i < numsSize; i++){
13+
num = nums[i];
14+
while (numsSet[num] != 0){
15+
numsSet[nums[leftIndex]] = 0;
16+
windowSumm -= nums[leftIndex];
17+
leftIndex++;
18+
}
19+
20+
numsSet[num] = 1;
21+
windowSumm += num;
22+
23+
if (maxSum < windowSumm){
24+
maxSum = windowSumm;
25+
}
26+
}
27+
28+
return maxSum;
29+
}

0 commit comments

Comments
 (0)