Skip to content

Commit 49202d9

Browse files
committed
weekly contest
1 parent cb455cc commit 49202d9

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
6+
class Solution {
7+
public:
8+
long long calculateScore(vector<string>& instructions, vector<int>& values) {
9+
int n = values.size();
10+
vector<bool> vis(n);
11+
long long score = 0;
12+
int idx = 0;
13+
while (0 <= idx and idx < n and not vis[idx]) {
14+
vis[idx] = true;
15+
if (instructions[idx] == "add") {
16+
score += values[idx];
17+
idx++;
18+
}
19+
else {
20+
idx += values[idx];
21+
}
22+
}
23+
return score;
24+
}
25+
};
26+
27+
28+
int main() {
29+
ios_base::sync_with_stdio(false);
30+
cin.tie(nullptr);
31+
32+
33+
34+
return 0;
35+
}

3523. Make Array Non-decreasing.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// https://leetcode.com/problems/make-array-non-decreasing
2+
// Observation based question, simplifies to prefix max
3+
//
4+
// Login behind code:
5+
// - start with the first number and loop to the right
6+
// - for any number smaller than it, we must combine it with the first one to keep it non-decreasing
7+
// - for any number >= cur, we can now treat it as the new start and repeat
8+
9+
#include <bits/stdc++.h>
10+
11+
using namespace std;
12+
13+
14+
class Solution {
15+
public:
16+
int maximumPossibleSize(vector<int>& nums) {
17+
int total = 0;
18+
int pref_max = 0;
19+
for (int num: nums) {
20+
if (num >= pref_max) {
21+
pref_max = num;
22+
total++;
23+
}
24+
}
25+
return total;
26+
}
27+
};
28+
29+
30+
int main() {
31+
ios_base::sync_with_stdio(false);
32+
cin.tie(nullptr);
33+
34+
35+
36+
return 0;
37+
}

0 commit comments

Comments
 (0)