def solution(n, t, edges):
graph = [[] for _ in range(n)]
for u, v in edges:
graph[u].append(v)
graph[v].append(u)
def dfs(node, parent):
size, time_sum = 1, 0
for child in graph[node]:
if child != parent:
c_size, c_time = dfs(child, node)
size += c_size
time_sum += c_time + t[child] * c_size
return size, time_sum
total_time = sum(t)
expected_times = [0] * n
def calculate_expected(node, parent, parent_contrib):
size, time_sum = dfs(node, parent)
expected_times[node] = t[node] + (time_sum + parent_contrib) / (n - 1)
for child in graph[node]:
if child != parent:
child_contrib = parent_contrib + (total_time - time_sum - t[child]) * (n - size)
calculate_expected(child, node, child_contrib / (n - 1))
calculate_expected(0, -1, 0)
return min(range(n), key=lambda i: expected_times[i])
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Company Name: Suvi
Role: Software Engineer
Batch eligible: 2024 grads only
Apply: https://job-boards.greenhouse.io/suki/jobs/6072793003
Itโs mentioned that itโs for tier 1 colleges, but you can also give it a try!!
Role: Software Engineer
Batch eligible: 2024 grads only
Apply: https://job-boards.greenhouse.io/suki/jobs/6072793003
Itโs mentioned that itโs for tier 1 colleges, but you can also give it a try!!
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Company Name: American Express
Role: SDE 1
Batch eligible: 2023 grads
Apply: https://travelhrportal.wd1.myworkdayjobs.com/Jobs/job/Gurgaon-India/Software-Development-Engineer-I_J-68957-1
Role: SDE 1
Batch eligible: 2023 grads
Apply: https://travelhrportal.wd1.myworkdayjobs.com/Jobs/job/Gurgaon-India/Software-Development-Engineer-I_J-68957-1
๐1
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Company Name: Ticket(dot)com
Role: Software Engineer
YOE: 0-2 years
Apply: https://jobs.lever.co/tiket/c88b7251-59df-4cee-b5ae-3bb2468974f1/
Role: Software Engineer
YOE: 0-2 years
Apply: https://jobs.lever.co/tiket/c88b7251-59df-4cee-b5ae-3bb2468974f1/
#include <vector>
#include <iostream>
using namespace std;
int solve(vector<vector<int>>& operations) {
const int MAX_N = 100001;
vector<int> diff(MAX_N + 1, 0);
for (const auto& op : operations) {
int l = op[0];
int r = op[1];
diff[l] += 1;
if (r + 1 <= MAX_N) {
diff[r + 1] -= 1;
}
}
int sum = 0;
int aa = 0;
for (int i = 1; i <= MAX_N; ++i) {
aa += diff[i];
if (aa % 2 != 0) {
sum += i;
}
}
return sum;
}
Flipping Switches โ
๐1
MOD = 10**9 + 7
def factorial(n, mod):
result = 1
for i in range(2, n + 1):
result = (result * i) % mod
return result
def mod_inv(a, p):
return pow(a, p - 2, p)
def comb(n, k, mod):
if k > n:
return 0
numerator = factorial(n, mod)
denominator = (factorial(k, mod) * factorial(n - k, mod)) % mod
return (numerator * mod_inv(denominator, mod)) % mod
def count_ways(N, C, V):
if V > C:
return 0
total_ways = 0
for i in range(V, C + 1):
total_ways = (total_ways + comb(C, i, MOD)) % MOD
return total_ways
N, C, V = map(int, input().split())
print(count_ways(N, C, V))
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Hello Connections,
We are hiring for our Client
Position: Analyst - Decision Science
Experience: 0-6month
Location : Bangalore- WFO
Skills: SQL, Python ,R and Tableau
A bachelorโs degree in Statistics or other quantitative disciplines such as Engineering, Applied Mathematics, etc from IIT and NIT.
Interested candidate can share their resume at aiman.bano@zyoin.com
Candidates from Bangalore location is preferred.
We are hiring for our Client
Position: Analyst - Decision Science
Experience: 0-6month
Location : Bangalore- WFO
Skills: SQL, Python ,R and Tableau
A bachelorโs degree in Statistics or other quantitative disciplines such as Engineering, Applied Mathematics, etc from IIT and NIT.
Interested candidate can share their resume at aiman.bano@zyoin.com
Candidates from Bangalore location is preferred.
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <iostream>.
#include <unordered_map>
#include <string>
string solve(const std::string &s) {
unordered_map<char, char> charValueMap = {
{'a', '0'}, {'b', '0'}, {'c', '0'}, {'d', '0'}, {'e', '0'},
{'f', '1'}, {'g', '1'}, {'h', '1'}, {'i', '1'}, {'j', '1'},
{'k', '0'}, {'l', '0'}, {'m', '0'}, {'n', '0'}, {'o', '0'},
{'p', '1'}, {'q', '1'}, {'r', '1'}, {'s', '1'}, {'t', '1'},
{'u', '0'}, {'v', '0'}, {'w', '0'}, {'x', '0'}, {'y', '0'},
{'z', '1'}
};
std::string binaryString;
for (char ch : s) {
binaryString += charValueMap[ch];
}
return binaryString;
}
int main() {
string inputString;
getline(std::cin, inputString);
string result = solve(inputString);
cout << result << std::endl;
return 0;
}
TEXAS 2
๐1๐ฅ1
def findParent(processNumber):
if processNumber == 1:
return None
left, right = 1, processNumber
while left < right:
mid = (left + right) // 2
children_up_to_mid = mid * (mid + 1) // 2
if children_up_to_mid < processNumber:
left = mid + 1
else:
right = mid
parent = left
children_up_to_parent = parent * (parent + 1) // 2
return parent if children_up_to_parent >= processNumber else parent - 1
Process Tree โ
๐1
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
vector<int> tree[MAXN];
vector<int> prefixSum;
vector<int> cost;
vector<int> parent;
int N, K;
void dfs(int node, int par, int currentSum) {
prefixSum[node] = currentSum + cost[node];
parent[node] = par;
for (int child : tree[node]) {
if (child != par) {
dfs(child, node, prefixSum[node]);
}
}
}
int solve(int N, int K, vector<int>& A, vector<vector<int>>& edges) {
cost = A;
prefixSum.assign(N, 0);
parent.assign(N, -1);
for (int i = 0; i < N; ++i) {
tree[i].clear();
}
for (auto& edge : edges) {
int u = edge[0] - 1;
int v = edge[1] - 1;
tree[u].push_back(v);
tree[v].push_back(u);
}
dfs(0, -1, 0);
int maxCandies = 0;
for (int i = 0; i < N; ++i) {
int remainingMoney = K;
int candies = 0;
for (int j = i; j != -1; j = parent[j]) {
if (remainingMoney >= cost[j]) {
remainingMoney -= cost[j];
candies++;
} else {
break;
}
}
maxCandies = max(maxCandies, candies);
}
return maxCandies;
}
Zepto โ
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
using namespace std;
int solve(int N, int K, const vector<int>& houses) {
unordered_map<int, int> houseIndex;
for (int i = 0; i < houses.size(); ++i) {
houseIndex[houses[i] - 1] = i + 1;
}
priority_queue<int> pq;
for (int i = 0; i < K; ++i) {
pq.push(houseIndex[i]);
}
int ans = pq.top();
for (int i = 1; i + K - 1 < N; ++i) {
pq.push(houseIndex[i + K - 1]);
while (!pq.empty() && pq.top() > houseIndex[i + K - 1]) {
pq.pop();
}
ans = min(ans, pq.top());
}
return ans;
}
Happy neighborhoodโ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define sz(c) c.size()
ll solve()
{
ll n, m, i, j;
ll k;
ll l, r;
string s;
cin >> s;
n = sz(s);
ll dp[n][5];
memset(dp, 0, sizeof(dp));
if (s[0] == 'a')
dp[0][0] = 1;
for (int i = 1; i < n; i++)
{
if (s[i] == 'a')
{
dp[i][0] = 1 + dp[i - 1][0];
}
else
dp[i][0] = dp[i - 1][0];
if (s[i] == 'e')
{
if (dp[i - 1][1] != 0)
dp[i][1] = 1 + dp[i - 1][1];
if (dp[i - 1][0] != 0)
dp[i][1] = max(dp[i][1], 1 + dp[i - 1][0]);
}
else
dp[i][1] = dp[i - 1][1];
if (s[i] == 'i')
{
if (dp[i - 1][2] != 0)
dp[i][2] = 1 + dp[i - 1][2];
if (dp[i - 1][1] != 0)
dp[i][2] = max(dp[i][2], 1 + dp[i - 1][1]);
}
else
dp[i][2] = dp[i - 1][2];
if (s[i] == 'o')
{
if (dp[i - 1][3] != 0)
dp[i][3] = 1 + dp[i - 1][3];
if (dp[i - 1][2] != 0)
dp[i][3] = max(dp[i][3], 1 + dp[i - 1][2]);
}
else
dp[i][3] = dp[i - 1][3];
if (s[i] == 'u')
{
if (dp[i - 1][4] != 0)
dp[i][4] = 1 + dp[i - 1][4];
if (dp[i - 1][3] != 0)
dp[i][4] = max(dp[i][4], 1 + dp[i - 1][3]);
}
else
dp[i][4] = dp[i - 1][4];
}
cout << dp[n - 1][4];
return 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
t = 1;
// cin>>t;
while (t--)
{
solve();
}
return 0;
}
//longest Vowel subsequence with ordered vowel โ
using namespace std;
#define endl '\n'
#define ll long long
#define sz(c) c.size()
ll solve()
{
ll n, m, i, j;
ll k;
ll l, r;
string s;
cin >> s;
n = sz(s);
ll dp[n][5];
memset(dp, 0, sizeof(dp));
if (s[0] == 'a')
dp[0][0] = 1;
for (int i = 1; i < n; i++)
{
if (s[i] == 'a')
{
dp[i][0] = 1 + dp[i - 1][0];
}
else
dp[i][0] = dp[i - 1][0];
if (s[i] == 'e')
{
if (dp[i - 1][1] != 0)
dp[i][1] = 1 + dp[i - 1][1];
if (dp[i - 1][0] != 0)
dp[i][1] = max(dp[i][1], 1 + dp[i - 1][0]);
}
else
dp[i][1] = dp[i - 1][1];
if (s[i] == 'i')
{
if (dp[i - 1][2] != 0)
dp[i][2] = 1 + dp[i - 1][2];
if (dp[i - 1][1] != 0)
dp[i][2] = max(dp[i][2], 1 + dp[i - 1][1]);
}
else
dp[i][2] = dp[i - 1][2];
if (s[i] == 'o')
{
if (dp[i - 1][3] != 0)
dp[i][3] = 1 + dp[i - 1][3];
if (dp[i - 1][2] != 0)
dp[i][3] = max(dp[i][3], 1 + dp[i - 1][2]);
}
else
dp[i][3] = dp[i - 1][3];
if (s[i] == 'u')
{
if (dp[i - 1][4] != 0)
dp[i][4] = 1 + dp[i - 1][4];
if (dp[i - 1][3] != 0)
dp[i][4] = max(dp[i][4], 1 + dp[i - 1][3]);
}
else
dp[i][4] = dp[i - 1][4];
}
cout << dp[n - 1][4];
return 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
t = 1;
// cin>>t;
while (t--)
{
solve();
}
return 0;
}
//longest Vowel subsequence with ordered vowel โ
๐1
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
vector<int> smallestLexicographicalSubsequence(vector<int>& hubs, int k) {
vector<int> result;
stack<int> st;
int n = hubs.size();
for (int i = 0; i < n; ++i) {
while (!st.empty() && st.top() > hubs[i] && st.size() + (n - i) > k) {
st.pop();
}
if (st.size() < k) {
st.push(hubs[i]);
}
}
while (!st.empty()) {
result.insert(result.begin(), st.top());
st.pop();
}
return result;
}