Skip to content

Commit 745b394

Browse files
committed
added 2593, 3264
1 parent 7e6586b commit 745b394

4 files changed

+94
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
2593. Find Score of an Array After Marking All Elements
3+
4+
LeetCode Daily Question for December 13, 2024
5+
6+
Runtime: 204 ms (beats 28.68%)
7+
Memory: 143.70 MB (beats 18.41%)
8+
*/
9+
10+
class Solution {
11+
public:
12+
long long findScore(vector<int>& nums) {
13+
unordered_set<int> marked;
14+
vector<pair<int, int>> sorted_nums;
15+
sorted_nums.reserve(nums.size());
16+
for (int i = 0; i < nums.size(); ++i) {
17+
sorted_nums.push_back({ i, nums[i] });
18+
}
19+
sort(sorted_nums.begin(), sorted_nums.end(), [](pair<int, int> x, pair<int, int> y){
20+
return x.second < y.second ? true :
21+
x.second == y.second ? x.first < y.first :
22+
false;
23+
});
24+
long long score = 0;
25+
for (const pair<int, int>& p : sorted_nums) {
26+
if (marked.count(p.first)) continue;
27+
score += p.second;
28+
marked.insert(p.first);
29+
if (p.first > 0) marked.insert(p.first - 1);
30+
if (p.first < nums.size()) marked.insert(p.first + 1);
31+
32+
}
33+
return score;
34+
}
35+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
2593. Find Score of an Array After Marking All Elements
3+
4+
LeetCode Daily Question for December 13, 2024
5+
6+
Runtime: 248 ms (beats 84.86%)
7+
Memory: 43.81 MB (beats 32.48%)
8+
"""
9+
10+
class Solution:
11+
def findScore(self, nums: List[int]) -> int:
12+
marked = set()
13+
score = 0
14+
for i, j in sorted(enumerate(nums), key=lambda x: x[1]):
15+
if i in marked:
16+
continue
17+
score += j
18+
marked.add(i)
19+
marked.add(i - 1)
20+
marked.add(i + 1)
21+
return score
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
3264. Final Array State After K Multiplication Operations I
3+
4+
LeetCode Daily Question for December 15, 2024
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 27.17 MB (beats 46.57%)
8+
*/
9+
10+
class Solution {
11+
public:
12+
vector<int> getFinalState(vector<int>& nums, int k, int multiplier) {
13+
for (int i = 0; i < k; ++i) {
14+
auto pos = nums.begin();
15+
for (auto it = nums.begin() + 1; it != nums.end(); ++it) {
16+
if (*it < *pos) pos = it;
17+
}
18+
*pos = *pos * multiplier;
19+
}
20+
return nums;
21+
}
22+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
3264. Final Array State After K Multiplication Operations I
3+
4+
LeetCode Daily Question for December 15, 2024
5+
6+
Runtime: 255 ms (beats 5.80%)
7+
Memory: 17.51 MB (beats 12.46%)
8+
"""
9+
10+
class Solution:
11+
def getFinalState(self, nums: List[int], k: int, multiplier: int) -> List[int]:
12+
return reduce(
13+
lambda x, _: [x[i] * multiplier if i == (min(enumerate(x), key = (lambda e: e[1]))[0]) else x[i] for i in range(len(x))],
14+
range(k),
15+
nums
16+
)

0 commit comments

Comments
 (0)