๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
int checking(map<string, int>& dictone, int given) {
int c = 0;
for (auto it = dictone.begin(); it != dictone.end();) {
if (it->second > given) {
c++;
++it;
} else {
it = dictone.erase(it);
}
}
return c;
}
vector<int> getUnexpiredTokens(int time_to_live, vector<string>& queries) {
map<string, int> dictone;
vector<int> final;
for (string& one : queries) {
istringstream iss(one);
vector<string> tokens;
string token;
while (iss >> token) {
tokens.push_back(token);
}
if (tokens[0] == "generate") {
dictone[tokens[1]] = stoi(tokens[2]) + time_to_live;
} else if (tokens[0] == "renew") {
dictone[tokens[1]] = stoi(tokens[2]) + time_to_live;
} else if (tokens[0] == "count") {
int ans = checking(dictone, stoi(tokens[1]));
final.push_back(ans);
}
}
return final;
}
int c = 0;
for (auto it = dictone.begin(); it != dictone.end();) {
if (it->second > given) {
c++;
++it;
} else {
it = dictone.erase(it);
}
}
return c;
}
vector<int> getUnexpiredTokens(int time_to_live, vector<string>& queries) {
map<string, int> dictone;
vector<int> final;
for (string& one : queries) {
istringstream iss(one);
vector<string> tokens;
string token;
while (iss >> token) {
tokens.push_back(token);
}
if (tokens[0] == "generate") {
dictone[tokens[1]] = stoi(tokens[2]) + time_to_live;
} else if (tokens[0] == "renew") {
dictone[tokens[1]] = stoi(tokens[2]) + time_to_live;
} else if (tokens[0] == "count") {
int ans = checking(dictone, stoi(tokens[1]));
final.push_back(ans);
}
}
return final;
}
๐1
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
int countWaveArrays(int n, vector<int>& arr, int m) {
vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(m + 1, vector<int>(2, 0)));
for (int j = 1; j <= m; ++j) {
if (arr[0] == -1 || arr[0] == j) {
dp[1][j][0] = 1;
dp[1][j][1] = 1;
}
}
for (int i = 2; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (arr[i - 1] == -1 || arr[i - 1] == j) {
int sumValley = 0;
for (int k = 1; k < j; ++k) {
sumValley = (sumValley + dp[i - 1][k][1]) % MOD;
}
dp[i][j][0] = sumValley;
int sumPeak = 0;
for (int k = j + 1; k <= m; ++k) {
sumPeak = (sumPeak + dp[i - 1][k][0]) % MOD;
}
dp[i][j][1] = sumPeak;
}
}
}
int result = 0;
for (int j = 1; j <= m; ++j) {
result = (result + dp[n][j][0]) % MOD;
result = (result + dp[n][j][1]) % MOD;
}
return result;
}
vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(m + 1, vector<int>(2, 0)));
for (int j = 1; j <= m; ++j) {
if (arr[0] == -1 || arr[0] == j) {
dp[1][j][0] = 1;
dp[1][j][1] = 1;
}
}
for (int i = 2; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (arr[i - 1] == -1 || arr[i - 1] == j) {
int sumValley = 0;
for (int k = 1; k < j; ++k) {
sumValley = (sumValley + dp[i - 1][k][1]) % MOD;
}
dp[i][j][0] = sumValley;
int sumPeak = 0;
for (int k = j + 1; k <= m; ++k) {
sumPeak = (sumPeak + dp[i - 1][k][0]) % MOD;
}
dp[i][j][1] = sumPeak;
}
}
}
int result = 0;
for (int j = 1; j <= m; ++j) {
result = (result + dp[n][j][0]) % MOD;
result = (result + dp[n][j][1]) % MOD;
}
return result;
}
๐2
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Company Name: Akamai Technology
๐ Job Title: Software Engineer
โ๐ป YOE: 2022, 2023 and 2024 grads
โก๏ธ Apply: https://akamaicareers.inflightcloud.com/jobdetails/aka_ext/035283
Please do share in your college grps and in case you are applying please react on this post:) ๐โค๏ธ
๐ Job Title: Software Engineer
โ๐ป YOE: 2022, 2023 and 2024 grads
โก๏ธ Apply: https://akamaicareers.inflightcloud.com/jobdetails/aka_ext/035283
Please do share in your college grps and in case you are applying please react on this post:) ๐โค๏ธ
๐1
def shuffle_strings(instr1, instr2, innum):
outstr = ""
len1, len2 = len(instr1), len(instr2)
index1, index2 = 0, 0
while index1 < len1 or index2 < len2:
if index1 < len1:
outstr += instr1[index1:index1 + innum]
index1 += innum
if index2 < len2:
outstr += instr2[index2:index2 + innum]
index2 += innum
return outstr
instr1 = input().strip()
instr2 = input().strip()
innum = int(input().strip())
outstr = shuffle_strings(instr1, instr2, innum)
print(outstr)
outstr = ""
len1, len2 = len(instr1), len(instr2)
index1, index2 = 0, 0
while index1 < len1 or index2 < len2:
if index1 < len1:
outstr += instr1[index1:index1 + innum]
index1 += innum
if index2 < len2:
outstr += instr2[index2:index2 + innum]
index2 += innum
return outstr
instr1 = input().strip()
instr2 = input().strip()
innum = int(input().strip())
outstr = shuffle_strings(instr1, instr2, innum)
print(outstr)
๐1
def cache_query_handler(cache_entries, queries):
cache = {}
for entry in cache_entries:
timestamp, key, value = entry
if key not in cache:
cache[key] = {}
cache[key][timestamp] = value
result = []
for query in queries:
key, timestamp = query
if key in cache and timestamp in cache[key]:
result.append(cache[key][timestamp])
else:
result.append(None)
return result
cache = {}
for entry in cache_entries:
timestamp, key, value = entry
if key not in cache:
cache[key] = {}
cache[key][timestamp] = value
result = []
for query in queries:
key, timestamp = query
if key in cache and timestamp in cache[key]:
result.append(cache[key][timestamp])
else:
result.append(None)
return result
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Kaplan is looking for 2024 grads !
Software Engineer Intern at Bangalore Location
3 months intern opportunity with basic teck Stack knowledge
Apply Now :
https://docs.google.com/forms/d/1Syixdq-4ECY0XxPQgk6F0Br-NkexrdYVEl3uoKgaQEU/edit#responses
Software Engineer Intern at Bangalore Location
3 months intern opportunity with basic teck Stack knowledge
Apply Now :
https://docs.google.com/forms/d/1Syixdq-4ECY0XxPQgk6F0Br-NkexrdYVEl3uoKgaQEU/edit#responses
โค1๐1
SinglyLinkedListNode* condense(SinglyLinkedListNode* head) {
if (!head) return nullptr;
unordered_set<int> seen;
SinglyLinkedListNode* current = head;
SinglyLinkedListNode* prev = nullptr;
while (current) {
if (seen.find(current->data) != seen.end()) {
prev->next = current->next;
} else {
seen.insert(current->data);
prev = current;
}
current = current->next;
}
return head;
}
Ion โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
int numPlayers(int k, vector<int> scores) {
sort(scores.begin(), scores.end(), greater<int>());
int rank = 1, s = 1, i = 0;
int count = 0;
while(i < int(scores.size())) {
//cout << scores[i] << endl;
int temp = scores[i];
if(scores[i] == 0) {
i++;
continue;
}
scores[i] = i + 1;
int val = i + 1;
if((i + 1) <= k)
count++;
else
break;
i++;
while(i < int(scores.size()) && temp == scores[i]) {
scores[i] = scores[i - 1];
i++;
if(scores[i] <= k)
count++;
}
}
return count;
}
Ion โ
๐1
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
class UnionFind {
vector<int> parent;
vector<int> rank;
vector<int> maxStrength;
public:
UnionFind(int n) {
parent.resize(n + 1);
rank.resize(n + 1, 0);
maxStrength.resize(n + 1);
for (int i = 1; i <= n; ++i) {
parent[i] = i;
maxStrength[i] = i;
}
}
int find(int u) {
if (parent[u] != u) {
parent[u] = find(parent[u]);
}
return parent[u];
}
void unionSets(int u, int v) {
int rootU = find(u);
int rootV = find(v);
if (rootU != rootV) {
if (rank[rootU] > rank[rootV]) {
parent[rootV] = rootU;
maxStrength[rootU] = max(maxStrength[rootU], maxStrength[rootV]);
} else if (rank[rootU] < rank[rootV]) {
parent[rootU] = rootV;
maxStrength[rootV] = max(maxStrength[rootU], maxStrength[rootV]);
} else {
parent[rootV] = rootU;
maxStrength[rootU] = max(maxStrength[rootU], maxStrength[rootV]);
rank[rootU]++;
}
}
}
int getMaxStrength(int u) {
return maxStrength[find(u)];
}
};
vector<int> networkSums(int n, int e, vector<int>& from, vector<int>& to) {
UnionFind uf(n);
vector<int> results;
int totalSum = 0;
for (int i = 0; i < e; ++i) {
int u = from[i];
int v = to[i];
uf.unionSets(u, v);
unordered_set<int> uniqueRoots;
totalSum = 0;
for (int j = 1; j <= n; ++j) {
uniqueRoots.insert(uf.find(j));
}
for (int root : uniqueRoots) {
totalSum += uf.getMaxStrength(root);
}
results.push_back(totalSum);
}
return results;
}
Ion โ
def getMinimumSum(arr):
n = len(arr)
if n < 3:
return -1
left_min = [float('inf')] * n
for i in range(1, n):
left_min[i] = min(left_min[i-1], arr[i-1])
right_min = [float('inf')] * n
for i in range(n-2, -1, -1):
right_min[i] = min(right_min[i+1], arr[i+1])
min_sum = float('inf')
found = False
for j in range(1, n - 1):
if left_min[j] < arr[j] and right_min[j] < arr[j]:
current_sum = left_min[j] + arr[j] + right_min[j]
min_sum = min(min_sum, current_sum)
found = True
return min_sum if found else -1
Ion โ
n = len(arr)
if n < 3:
return -1
left_min = [float('inf')] * n
for i in range(1, n):
left_min[i] = min(left_min[i-1], arr[i-1])
right_min = [float('inf')] * n
for i in range(n-2, -1, -1):
right_min[i] = min(right_min[i+1], arr[i+1])
min_sum = float('inf')
found = False
for j in range(1, n - 1):
if left_min[j] < arr[j] and right_min[j] < arr[j]:
current_sum = left_min[j] + arr[j] + right_min[j]
min_sum = min(min_sum, current_sum)
found = True
return min_sum if found else -1
Ion โ
def getMinimumTime(requestedServers, transitionTime):
n = len(requestedServers)
m = len(transitionTime)
min_time = 0
for i in range(1, n):
current = requestedServers[i] - 1
previous = requestedServers[i-1] - 1
distance = min((current - previous) % m, (previous - current) % m)
min_time += distance * transitionTime[previous]
return min_time
#include <vector>
#include <algorithm>
int getMinimumTime(const std::vector<int>& requestedServers, const std::vector<int>& transitionTime) {
int n = requestedServers.size();
int m = transitionTime.size();
int min_time = 0;
for (int i = 1; i < n; i++) {
int current = requestedServers[i] - 1;
int previous = requestedServers[i - 1] - 1;
int distance = std::min((current - previous + m) % m, (previous - current + m) % m);
min_time += distance * transitionTime[previous];
}
return min_time;
}
Get Minimum Time โ
โค1
import heapq
class GPUAllocator:
def __init__(self):
self.available_gpus = []
self.max_gpu_id = 10**6
self.next_gpu_id = 1
self.add_gpus(self.max_gpu_id)
def add_gpus(self, count):
for _ in range(count):
heapq.heappush(self.available_gpus, self.next_gpu_id)
self.next_gpu_id += 1
def smallestUnoccupied(self):
if not self.available_gpus:
self.add_gpus(100)
return self.available_gpus[0] if self.available_gpus else -1
# Example usage
allocator = GPUAllocator()
print(allocator.smallestUnoccupied())
print(allocator.smallestUnoccupied())
GPU