#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool helper(const vector<int>& prices, int k, int minDiff) {
int count = 1;
int last = prices[0];
for (int i = 1; i < prices.size(); ++i) {
if (prices[i] - last >= minDiff) {
count++;
last = prices[i];
if (count >= k)
return true;
}
}
return false;
}
int solve(vector<int>& prices, int k) {
sort(prices.begin(), prices.end());
int left = 1;
int right = prices.back() - prices.front();
int result = 0;
while (left <= right) {
int mid = left + (right - left) / 2;
if (helper(prices, k, mid)) {
result = mid;
left = mid + 1;
} else {
right = mid - 1;
}
}
return result;
}
SALESFORCE
MAXIMUM VALUE AND MINIMUM DIffโ
#include <vector>
#include <algorithm>
using namespace std;
bool helper(const vector<int>& prices, int k, int minDiff) {
int count = 1;
int last = prices[0];
for (int i = 1; i < prices.size(); ++i) {
if (prices[i] - last >= minDiff) {
count++;
last = prices[i];
if (count >= k)
return true;
}
}
return false;
}
int solve(vector<int>& prices, int k) {
sort(prices.begin(), prices.end());
int left = 1;
int right = prices.back() - prices.front();
int result = 0;
while (left <= right) {
int mid = left + (right - left) / 2;
if (helper(prices, k, mid)) {
result = mid;
left = mid + 1;
} else {
right = mid - 1;
}
}
return result;
}
SALESFORCE
MAXIMUM VALUE AND MINIMUM DIffโ
๐1
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
#include <iostream> #include <vector> #include <algorithm> using namespace std; bool helper(const vector<int>& prices, int k, int minDiff) { int count = 1; int last = prices[0]; for (int i = 1; i < prices.size(); ++i) { if (prices[i] -โฆ
import itertools
import sys
def find_distance_time(values):
for uSpeed, uAlpha, uBeta, uDelta in itertools.permutations(values):
for distance in range(1, 10**5 + 1):
time_1 = uAlpha - distance
time_2 = distance - uDelta
if time_1 > 0 and distance // time_1 == uSpeed and distance * time_1 == uBeta:
return (distance, time_1)
if time_2 > 0 and distance // time_2 == uSpeed and distance * time_2 == uBeta:
return (distance, time_2)
return -1, -1
def main():
input = sys.stdin.read
data = input().split()
t = int(data[0])
index = 1
results = []
for _ in range(t):
test_case = list(map(int, data[index:index+4]))
index += 4
distance, time = find_distance_time(test_case)
results.append(f'{distance} {time}')
for result in results:
print(result)
if __name__ == "__main__":
main()
Uber 4 try it
def solution(A, B, C):
last_two = ["", ""]
cnt = [A, B, C]
ans = []
while sum(cnt):
for ind, letter in enumerate("abc"):
if last_two[0] == last_two[1] and last_two[0] == letter:
continue
if not cnt[ind]:
continue
cnt2 = list(cnt)
cnt2[ind] -= 1
max_cnt = max(cnt2)
sum_cnt_not_max = sum(cnt2) - max_cnt
if max_cnt > sum_cnt_not_max * 2 + 2:
continue
last_two[0] = last_two[1]
last_two[1] = letter
cnt[ind] -= 1
ans.append(letter)
break
return "".join(ans)
Smallest Diverse String โ
Salesforce
last_two = ["", ""]
cnt = [A, B, C]
ans = []
while sum(cnt):
for ind, letter in enumerate("abc"):
if last_two[0] == last_two[1] and last_two[0] == letter:
continue
if not cnt[ind]:
continue
cnt2 = list(cnt)
cnt2[ind] -= 1
max_cnt = max(cnt2)
sum_cnt_not_max = sum(cnt2) - max_cnt
if max_cnt > sum_cnt_not_max * 2 + 2:
continue
last_two[0] = last_two[1]
last_two[1] = letter
cnt[ind] -= 1
ans.append(letter)
break
return "".join(ans)
Smallest Diverse String โ
Salesforce
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
class UnionFind {
public:
UnionFind(int n) {
p = vector<int>(n);
size = vector<int>(n, 1);
iota(p.begin(), p.end(), 0);
}
bool unite(int a, int b) {
int pa = find(a), pb = find(b);
if (pa == pb) {
return false;
}
if (size[pa] > size[pb]) {
p[pb] = pa;
size[pa] += size[pb];
} else {
p[pa] = pb;
size[pb] += size[pa];
}
return true;
}
int find(int x) {
if (p[x] != x) {
p[x] = find(p[x]);
}
return p[x];
}
int getSize(int root) {
return size[root];
}
private:
vector<int> p, size;
};
class Solution {
public:
int minMalwareSpread(vector<vector<int>>& graph, vector<int>& initial) {
int n = graph.size();
bool s[n];
memset(s, false, sizeof(s));
for (int i : initial) {
s[i] = true;
}
UnionFind uf(n);
for (int i = 0; i < n; ++i) {
if (!s[i]) {
for (int j = i + 1; j < n; ++j) {
if (graph[i][j] && !s[j]) {
uf.unite(i, j);
}
}
}
}
unordered_set<int> g[n];
int cnt[n];
memset(cnt, 0, sizeof(cnt));
for (int i : initial) {
for (int j = 0; j < n; ++j) {
if (!s[j] && graph[i][j]) {
g[i].insert(uf.find(j));
}
}
for (int root : g[i]) {
++cnt[root];
}
}
int ans = 0, mx = -1;
for (int i : initial) {
int t = 0;
for (int root : g[i]) {
if (cnt[root] == 1) {
t += uf.getSize(root);
}
}
if (t > mx || (t == mx && i < ans)) {
ans = i;
mx = t;
}
}
return ans;
}
};
Malware spread โ
public:
UnionFind(int n) {
p = vector<int>(n);
size = vector<int>(n, 1);
iota(p.begin(), p.end(), 0);
}
bool unite(int a, int b) {
int pa = find(a), pb = find(b);
if (pa == pb) {
return false;
}
if (size[pa] > size[pb]) {
p[pb] = pa;
size[pa] += size[pb];
} else {
p[pa] = pb;
size[pb] += size[pa];
}
return true;
}
int find(int x) {
if (p[x] != x) {
p[x] = find(p[x]);
}
return p[x];
}
int getSize(int root) {
return size[root];
}
private:
vector<int> p, size;
};
class Solution {
public:
int minMalwareSpread(vector<vector<int>>& graph, vector<int>& initial) {
int n = graph.size();
bool s[n];
memset(s, false, sizeof(s));
for (int i : initial) {
s[i] = true;
}
UnionFind uf(n);
for (int i = 0; i < n; ++i) {
if (!s[i]) {
for (int j = i + 1; j < n; ++j) {
if (graph[i][j] && !s[j]) {
uf.unite(i, j);
}
}
}
}
unordered_set<int> g[n];
int cnt[n];
memset(cnt, 0, sizeof(cnt));
for (int i : initial) {
for (int j = 0; j < n; ++j) {
if (!s[j] && graph[i][j]) {
g[i].insert(uf.find(j));
}
}
for (int root : g[i]) {
++cnt[root];
}
}
int ans = 0, mx = -1;
for (int i : initial) {
int t = 0;
for (int root : g[i]) {
if (cnt[root] == 1) {
t += uf.getSize(root);
}
}
if (t > mx || (t == mx && i < ans)) {
ans = i;
mx = t;
}
}
return ans;
}
};
Malware spread โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
def smallest_lexicographical_string(word, max_operations):
operations_used = 0
word = list(word) # Convert to list for easier manipulation
for i in range(len(word)):
if operations_used >= max_operations:
break
current_char = word[i]
if current_char == 'a':
continue
# Number of operations needed to turn current character into 'a'
operations_needed = ord(current_char) - ord('a')
if operations_used + operations_needed <= max_operations:
word[i] = 'a'
operations_used += operations_needed
else:
# Change as much as possible
new_char = chr(ord(current_char) - (max_operations - operations_used))
word[i] = new_char
operations_used = max_operations
break
return ''.join(word)
Optimal storage โ
operations_used = 0
word = list(word) # Convert to list for easier manipulation
for i in range(len(word)):
if operations_used >= max_operations:
break
current_char = word[i]
if current_char == 'a':
continue
# Number of operations needed to turn current character into 'a'
operations_needed = ord(current_char) - ord('a')
if operations_used + operations_needed <= max_operations:
word[i] = 'a'
operations_used += operations_needed
else:
# Change as much as possible
new_char = chr(ord(current_char) - (max_operations - operations_used))
word[i] = new_char
operations_used = max_operations
break
return ''.join(word)
Optimal storage โ
๐1
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Company Name: Siemens
๐ Job Title: Software Developer (C#, .NET)
โ๐ป YOE: 0-2 years
โก๏ธ Apply: https://jobs.siemens.com/careers/job/563156119889279-software-developer-c-net-0-2-years--pune-maharashtra-india
Please do share in your college grps and in case you are applying please react on this post:) ๐โค๏ธ
๐ Job Title: Software Developer (C#, .NET)
โ๐ป YOE: 0-2 years
โก๏ธ Apply: https://jobs.siemens.com/careers/job/563156119889279-software-developer-c-net-0-2-years--pune-maharashtra-india
Please do share in your college grps and in case you are applying please react on this post:) ๐โค๏ธ
๐1
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Company Name: GeeksForGeeks
๐ Job Title: Problem Setter Intern
โ๐ป YOE: 2025, 2026 and 2027 grads
โก๏ธ Apply: https://docs.google.com/forms/d/e/1FAIpQLScwjzdptkkP51CW7_C2psA2kdMBlW7NitkAb0_pxufFboxjlw/viewform
Please do share in your college grps and in case you are applying please react on this post:) ๐โค๏ธ
๐ Job Title: Problem Setter Intern
โ๐ป YOE: 2025, 2026 and 2027 grads
โก๏ธ Apply: https://docs.google.com/forms/d/e/1FAIpQLScwjzdptkkP51CW7_C2psA2kdMBlW7NitkAb0_pxufFboxjlw/viewform
Please do share in your college grps and in case you are applying please react on this post:) ๐โค๏ธ
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)