void dfs(int node, vector<vector<int>>& tree, vector<bool>& visited, vector<bool>& cursed) {
visited[node] = true;
for (int neighbor : tree[node]) {
if (!visited[neighbor] && !cursed[neighbor]) {
dfs(neighbor, tree, visited, cursed);
}
}
}
int maxUncursedNodes(int n, vector<vector<int>>& edges) {
if (n == 1) return 1;
vector<vector<int>> tree(n + 1);
vector<bool> cursed(n + 1, false);
for (auto& edge : edges) {
int u = edge[0];
int v = edge[1];
tree[u].push_back(v);
tree[v].push_back(u);
}
cursed[1] = true;
vector<bool> visited(n + 1, false);
dfs(1, tree, visited, cursed);
int uncursedCount = 0;
for (int i = 2; i <= n; ++i) {
if (!visited[i]) {
uncursedCount++;
}
}
return uncursedCount+2;
}
visited[node] = true;
for (int neighbor : tree[node]) {
if (!visited[neighbor] && !cursed[neighbor]) {
dfs(neighbor, tree, visited, cursed);
}
}
}
int maxUncursedNodes(int n, vector<vector<int>>& edges) {
if (n == 1) return 1;
vector<vector<int>> tree(n + 1);
vector<bool> cursed(n + 1, false);
for (auto& edge : edges) {
int u = edge[0];
int v = edge[1];
tree[u].push_back(v);
tree[v].push_back(u);
}
cursed[1] = true;
vector<bool> visited(n + 1, false);
dfs(1, tree, visited, cursed);
int uncursedCount = 0;
for (int i = 2; i <= n; ++i) {
if (!visited[i]) {
uncursedCount++;
}
}
return uncursedCount+2;
}
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Adobe Hiring!!
Role - sde
Exp - 0 year
Link - https://careers.adobe.com/us/en/job/ADOBUSR146901EXTERNALENUS/Software-Development-Engineer
Role - sde
Exp - 0 year
Link - https://careers.adobe.com/us/en/job/ADOBUSR146901EXTERNALENUS/Software-Development-Engineer
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Cosmocloud hiring Interns and Part time engineers
Batches 2025/2024/2023 eligible for internship
Batches 2022/2021/2020 ( 2+ year experience ) eligible
Apply Here :
https://forms.gle/rFkNQry9ztF32Yph8
Batches 2025/2024/2023 eligible for internship
Batches 2022/2021/2020 ( 2+ year experience ) eligible
Apply Here :
https://forms.gle/rFkNQry9ztF32Yph8
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
long long dp[2005][2005];
long long rec(int level, int i, int n, int m, std::vector<int>& a, std::vector<int>& b) {
if (level == m) {
return 0;
}
if (dp[level][i] != -1) {
return dp[level][i];
}
int j = n - level + i - 1;
long long ans = rec(level + 1, i + 1, n, m, a, b) + ((long long)a[i]) * b[level];
ans = std::max(ans, rec(level + 1, i, n, m, a, b) + ((long long)a[j]) * b[level]);
return dp[level][i] = ans;
}
long getMaxTotalCompatibility(std::vector<int> hardware_compatibility, std::vector<int> computer_compatibility) {
int n = hardware_compatibility.size();
int m = computer_compatibility.size();
for (int i = 0; i <= m; i++) {
for (int j = 0; j <= m; j++) {
dp[i][j] = -1;
}
}
return rec(0, 0, n, m, hardware_compatibility, computer_compatibility);
}
DE Shaw โ
long long rec(int level, int i, int n, int m, std::vector<int>& a, std::vector<int>& b) {
if (level == m) {
return 0;
}
if (dp[level][i] != -1) {
return dp[level][i];
}
int j = n - level + i - 1;
long long ans = rec(level + 1, i + 1, n, m, a, b) + ((long long)a[i]) * b[level];
ans = std::max(ans, rec(level + 1, i, n, m, a, b) + ((long long)a[j]) * b[level]);
return dp[level][i] = ans;
}
long getMaxTotalCompatibility(std::vector<int> hardware_compatibility, std::vector<int> computer_compatibility) {
int n = hardware_compatibility.size();
int m = computer_compatibility.size();
for (int i = 0; i <= m; i++) {
for (int j = 0; j <= m; j++) {
dp[i][j] = -1;
}
}
return rec(0, 0, n, m, hardware_compatibility, computer_compatibility);
}
DE Shaw โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
def can_download_all_files(k, files, latency):
remaining_files = files.copy()
time = 0
while any(remaining_files):
if k <= 0:
return False
max_latency = 0
for i in range(len(remaining_files)):
if remaining_files[i] > 0:
downloaded = min(k, remaining_files[i])
remaining_files[i] -= downloaded
if remaining_files[i] > 0:
max_latency = max(max_latency, latency[i])
k -= max_latency
time += 1
return True
def get_min_server_speed(files, latency):
low, high = 1, max(files)
while low < high:
mid = (low + high) // 2
if can_download_all_files(mid, files, latency):
high = mid
else:
low = mid + 1
return low
n = int(input())
files = list(map(int, input().split()))
latency = list(map(int, input().split()))
result = get_min_server_speed(files, latency)
print(result)
DE Shaw โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
def get_level(rating):
if rating < 1000:
return "beginner"
elif rating < 1500:
return "intermediate"
elif rating < 2000:
return "advanced"
else:
return "pro"
def solution(initial, changes):
rating = initial
for change in changes:
rating += change
rating = max(1, min(2500, rating))
return get_level(rating)
if rating < 1000:
return "beginner"
elif rating < 1500:
return "intermediate"
elif rating < 2000:
return "advanced"
else:
return "pro"
def solution(initial, changes):
rating = initial
for change in changes:
rating += change
rating = max(1, min(2500, rating))
return get_level(rating)
def change_directory(commands):
current_directory = ['/']
for command in commands:
if command == 'cd /':
current_directory = ['/']
elif command == 'cd .':
continue
elif command == 'cd -':
if len(current_directory) > 1:
current_directory.pop()
elif command.startswith('cd '):
subdirectory = command.split(' ')[1]
current_directory.append(subdirectory)
return '/' + '/'.join(current_directory[1:])
current_directory = ['/']
for command in commands:
if command == 'cd /':
current_directory = ['/']
elif command == 'cd .':
continue
elif command == 'cd -':
if len(current_directory) > 1:
current_directory.pop()
elif command.startswith('cd '):
subdirectory = command.split(' ')[1]
current_directory.append(subdirectory)
return '/' + '/'.join(current_directory[1:])
๐1
def subsequence_sums_xor(arr):
n = len(arr)
all_sums = {0} # Start with the empty subsequence sum
for num in arr:
new_sums = set()
for s in all_sums:
new_sums.add(s + num)
all_sums.update(new_sums)
result_xor = 0
for sum_value in all_sums:
result_xor ^= sum_value
return result_xor
Array subsequence sums โ
n = len(arr)
all_sums = {0} # Start with the empty subsequence sum
for num in arr:
new_sums = set()
for s in all_sums:
new_sums.add(s + num)
all_sums.update(new_sums)
result_xor = 0
for sum_value in all_sums:
result_xor ^= sum_value
return result_xor
Array subsequence sums โ
SELECT
u.email,
COUNT(t.amount) AS total_transactions,
MIN(t.amount) AS min_amount,
MAX(t.amount) AS max_amount,
SUM(t.amount) AS total_amount
FROM
users u
JOIN
transactions t ON u.id = t.user_id
WHERE
t.dt >= '2024-03-01' AND t.dt < '2024-04-01'
GROUP BY
u.email
ORDER BY
u.email;
User Transaction Details โ
def findMaxGuests(arrl, exit, n):
arrl.sort()
exit.sort()
guests_in = 1
max_guests = 1
time = arrl[0]
i = 1
j = 0
while i < n and j < n:
if arrl[i] <= exit[j]:
guests_in += 1
if guests_in > max_guests:
max_guests = guests_in
time = arrl[i]
i += 1
else:
guests_in -= 1
j += 1
return time
Adobe โ
arrl.sort()
exit.sort()
guests_in = 1
max_guests = 1
time = arrl[0]
i = 1
j = 0
while i < n and j < n:
if arrl[i] <= exit[j]:
guests_in += 1
if guests_in > max_guests:
max_guests = guests_in
time = arrl[i]
i += 1
else:
guests_in -= 1
j += 1
return time
Adobe โ
#include <cstdio>
#include <algorithm>
const int maxN = 2 * 1e7 + 5;
long long dp1[maxN], dp2[maxN], dp3[maxN];
long long ans, ans1, ans2, ans3, pom;
int n, idx, l[5000];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &l[i]);
}
std::sort(l, l + n);
for (int i = 0; i < n; i++) {
dp1[l[i]]++;
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
dp2[l[i] + l[j]]++;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (l[i] != l[i - 1]) {
dp3[l[i]] += dp2[l[i] - l[j]];
if (3 * l[j] == l[i]) {
dp3[l[i]] -= (dp1[l[j]] - 1);
} else if (2 * l[j] < l[i]) {
dp3[l[i]] -= dp1[l[i] - 2 * l[j]];
}
}
}
}
for (int i = 1; i < n; i++) {
if (l[i] != l[i - 1]) {
dp3[l[i]] = dp3[l[i]] / 3;
}
}
ans = 0;
for (int i = 1; i < n; i++) {
if (l[i] != l[i - 1]) {
ans += (dp1[l[i]] * (dp1[l[i]] - 1) * (dp1[l[i]] - 2) * dp3[l[i]]) / 6;
}
}
for (int i = 1; i < n; i++) {
if (l[i] != l[i - 1]) {
idx = 0;
pom = 0;
ans2 = 0;
ans3 = 0;
while (2 * l[idx] < l[i]) {
if (pom != l[idx]) {
pom = l[idx];
ans3 += (dp1[l[idx]] * (dp1[l[idx]] - 1) * dp1[l[i] - l[idx]] * (dp1[l[i] - l[idx]] - 1)) / 4;
if (l[i] % 2 == 0) {
ans3 += (dp1[l[idx]] * dp1[l[i] - l[idx]] * dp1[l[i] / 2] * (dp1[l[i] / 2] - 1)) / 2;
ans2 += dp1[l[idx]] * dp1[l[i] - l[idx]] * (dp2[l[i]] - (dp1[l[idx]] * dp1[l[i] - l[idx]]) - (dp1[l[i] / 2] * (dp1[l[i] / 2] - 1)) / 2);
} else {
ans2 += (dp1[l[idx]] * dp1[l[i] - l[idx]]) * (dp2[l[i]] - (dp1[l[idx]] * dp1[l[i] - l[idx]]));
}
}
idx++;
}
ans2 = ans2 / 2;
ans2 += ans3;
if (2 * l[idx] == l[i]) {
ans2 += (dp1[l[idx]] * (dp1[l[idx]] - 1) * (dp1[l[idx]] - 2) * (dp1[l[idx]] - 3)) / 24;
}
ans1 += ans2 * (dp1[l[i]] * (dp1[l[i]] - 1)) / 2;
}
}
ans += ans1;
printf("%lld", ans);
return 0;
}
Magical sticks โ
#include <algorithm>
const int maxN = 2 * 1e7 + 5;
long long dp1[maxN], dp2[maxN], dp3[maxN];
long long ans, ans1, ans2, ans3, pom;
int n, idx, l[5000];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &l[i]);
}
std::sort(l, l + n);
for (int i = 0; i < n; i++) {
dp1[l[i]]++;
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
dp2[l[i] + l[j]]++;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (l[i] != l[i - 1]) {
dp3[l[i]] += dp2[l[i] - l[j]];
if (3 * l[j] == l[i]) {
dp3[l[i]] -= (dp1[l[j]] - 1);
} else if (2 * l[j] < l[i]) {
dp3[l[i]] -= dp1[l[i] - 2 * l[j]];
}
}
}
}
for (int i = 1; i < n; i++) {
if (l[i] != l[i - 1]) {
dp3[l[i]] = dp3[l[i]] / 3;
}
}
ans = 0;
for (int i = 1; i < n; i++) {
if (l[i] != l[i - 1]) {
ans += (dp1[l[i]] * (dp1[l[i]] - 1) * (dp1[l[i]] - 2) * dp3[l[i]]) / 6;
}
}
for (int i = 1; i < n; i++) {
if (l[i] != l[i - 1]) {
idx = 0;
pom = 0;
ans2 = 0;
ans3 = 0;
while (2 * l[idx] < l[i]) {
if (pom != l[idx]) {
pom = l[idx];
ans3 += (dp1[l[idx]] * (dp1[l[idx]] - 1) * dp1[l[i] - l[idx]] * (dp1[l[i] - l[idx]] - 1)) / 4;
if (l[i] % 2 == 0) {
ans3 += (dp1[l[idx]] * dp1[l[i] - l[idx]] * dp1[l[i] / 2] * (dp1[l[i] / 2] - 1)) / 2;
ans2 += dp1[l[idx]] * dp1[l[i] - l[idx]] * (dp2[l[i]] - (dp1[l[idx]] * dp1[l[i] - l[idx]]) - (dp1[l[i] / 2] * (dp1[l[i] / 2] - 1)) / 2);
} else {
ans2 += (dp1[l[idx]] * dp1[l[i] - l[idx]]) * (dp2[l[i]] - (dp1[l[idx]] * dp1[l[i] - l[idx]]));
}
}
idx++;
}
ans2 = ans2 / 2;
ans2 += ans3;
if (2 * l[idx] == l[i]) {
ans2 += (dp1[l[idx]] * (dp1[l[idx]] - 1) * (dp1[l[idx]] - 2) * (dp1[l[idx]] - 3)) / 24;
}
ans1 += ans2 * (dp1[l[i]] * (dp1[l[i]] - 1)) / 2;
}
}
ans += ans1;
printf("%lld", ans);
return 0;
}
Magical sticks โ
๐1
def best_sum_downward_tree_path(parent, values):
dp = [0] * len(parent)
max_value = float('-inf')
for i in range(len(parent)):
p = parent[i]
value = values[i]
dp[i] = value if p == -1 else max(dp[p] + value, value)
max_value = max(dp[i], max_value)
return max_value
Best sum download Tree Path
Adobe โ
dp = [0] * len(parent)
max_value = float('-inf')
for i in range(len(parent)):
p = parent[i]
value = values[i]
dp[i] = value if p == -1 else max(dp[p] + value, value)
max_value = max(dp[i], max_value)
return max_value
Best sum download Tree Path
Adobe โ