commit a3f44daa25c2a8d48b64738c65a728082d91448e
parent 9a0d9277f267db3bc5581c3a328ff5712a3d5424
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sat, 16 Mar 2024 12:37:31 +0000
Daily Problem
Diffstat:
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/Problems/0525.cpp b/Problems/0525.cpp
@@ -0,0 +1,19 @@
+class Solution {
+ public:
+ int findMaxLength(const vector<int> &nums) const {
+ unordered_map<int, int> um;
+ int res = 0, sum = 0;
+
+ um.emplace(0, -1);
+ for (int i = 0; i < size(nums); i++) {
+ sum += nums[i] ? 1 : -1;
+ auto it = um.find(sum);
+ if (it != end(um))
+ res = max(res, i - it->second);
+ else
+ um.emplace(sum, i);
+ }
+
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -362,6 +362,7 @@ for solving problems.
| 0516 | Medium | [Longest Palindromic Subsequence](Problems/0516.cpp) |
| 0518 | Medium | [Coin Change II](Problems/0518.cpp) |
| 0520 | Easy | [Detect Capital](Problems/0520.cpp) |
+| 0525 | Medium | [Contiguous Array](Problems/0525.cpp) |
| 0526 | Medium | [Beautiful Arrangement](Problems/0526.cpp) |
| 0529 | Medium | [Minesweeper](Problems/0529.cpp) |
| 0530 | Easy | [Minimum Absolute Difference in BST](Problems/0530.cpp) |