-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add problems from Biweekly Contest 44.
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
solved/LeetCode/1732. Find the Highest Altitude/solution.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Solution { | ||
fun largestAltitude(gain: IntArray): Int { | ||
var cur = 0 | ||
var best = 0 | ||
for (i in gain) { | ||
cur += i | ||
best = best.coerceAtLeast(cur) | ||
} | ||
return best | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
solved/LeetCode/1733. Minimum Number of People to Teach/solution.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class Solution { | ||
public: | ||
int minimumTeachings(int n, vector<vector<int>>& languages, vector<vector<int>>& friendships) { | ||
memo = vector<vector<int>>(501, vector<int>(501, -1)); | ||
|
||
vector<set<int>> lang(languages.size()); | ||
for (int i = 0; i < languages.size(); i++) { | ||
for (auto it : languages[i]) lang[i].insert(it); | ||
} | ||
|
||
int best = languages.size(); | ||
for (int cur = 0; cur < n; cur++) { | ||
set<int> toTeach; | ||
for (auto& fri : friendships) { | ||
assert(fri.size() == 2); | ||
if (!CanTalk(fri[0] - 1, fri[1] - 1, languages)) { | ||
for (auto person : fri) { | ||
if (lang[person - 1].count(cur) == 0) { | ||
toTeach.insert(person); | ||
} | ||
} | ||
} | ||
} | ||
best = min<int>(toTeach.size(), best); | ||
} | ||
return best; | ||
} | ||
|
||
private: | ||
bool CanTalk(int a, int b, const vector<vector<int>>& lang) { | ||
if (memo[a][b] != -1) return memo[a][b]; | ||
|
||
set<int> A(lang[a].begin(), lang[a].end()); | ||
for (auto it : lang[b]) { | ||
if (A.count(it)) { | ||
return memo[a][b] = 1; | ||
} | ||
} | ||
return memo[a][b] = 0; | ||
} | ||
|
||
vector<vector<int>> memo; | ||
}; |
15 changes: 15 additions & 0 deletions
15
solved/LeetCode/1734. Decode XORed Permutation/solution.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Solution { | ||
public: | ||
vector<int> decode(vector<int>& encoded) { | ||
vector<int> ans(encoded.size() + 1); | ||
int extra = ((ans.size() + 1) / 2) & 1; | ||
for (int i = 1; i < encoded.size(); i+=2) { | ||
extra ^= encoded[i]; | ||
} | ||
ans[0] = extra; | ||
for (int i = 1; i < ans.size(); i++) { | ||
ans[i] = ans[i-1] ^ encoded[i-1]; | ||
} | ||
return ans; | ||
} | ||
}; |