๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
import heapq
def minCost(g_nodes, g_from, g_to, g_weight):
adj_list = [[] for _ in range(g_nodes)]
for i in range(len(g_from)):
adj_list[g_from[i] - 1].append((g_to[i] - 1, g_weight[i]))
new_edges = []
for i in range(g_nodes):
for j in range(g_nodes):
if i != j and (i+1, j+1) not in zip(g_from, g_to):
new_edges.append((i, j, 1))
for i, j, w in new_edges:
adj_list[i].append((j, w))
distances = [float('inf')] * g_nodes
distances[0] = 0
pq = [(0, 0)]
while pq:
dist, node = heapq.heappop(pq)
if dist > distances[node]:
continue
for neighbor, weight in adj_list[node]:
new_dist = dist + weight
if new_dist < distances[neighbor]:
distances[neighbor] = new_dist
heapq.heappush(pq, (new_dist, neighbor))
return distances[-1]
DP World โ
Minimum weight path in a directed path
def minCost(g_nodes, g_from, g_to, g_weight):
adj_list = [[] for _ in range(g_nodes)]
for i in range(len(g_from)):
adj_list[g_from[i] - 1].append((g_to[i] - 1, g_weight[i]))
new_edges = []
for i in range(g_nodes):
for j in range(g_nodes):
if i != j and (i+1, j+1) not in zip(g_from, g_to):
new_edges.append((i, j, 1))
for i, j, w in new_edges:
adj_list[i].append((j, w))
distances = [float('inf')] * g_nodes
distances[0] = 0
pq = [(0, 0)]
while pq:
dist, node = heapq.heappop(pq)
if dist > distances[node]:
continue
for neighbor, weight in adj_list[node]:
new_dist = dist + weight
if new_dist < distances[neighbor]:
distances[neighbor] = new_dist
heapq.heappush(pq, (new_dist, neighbor))
return distances[-1]
DP World โ
Minimum weight path in a directed path
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
import heapq
def maxClusterQuality(speeds, reliabilities, max_size):
machines = sorted(zip(reliabilities, speeds), reverse=True)
max_quality = 0
current_sum = 0
min_heap = []
for reliability, speed in machines:
heapq.heappush(min_heap, speed)
current_sum += speed
if len(min_heap) > max_size:
current_sum -= heapq.heappop(min_heap)
if len(min_heap) <= max_size:
max_quality = max(max_quality, current_sum * reliability)
return max_quality
Computing Cluster Quality โ
DP World
def maxClusterQuality(speeds, reliabilities, max_size):
machines = sorted(zip(reliabilities, speeds), reverse=True)
max_quality = 0
current_sum = 0
min_heap = []
for reliability, speed in machines:
heapq.heappush(min_heap, speed)
current_sum += speed
if len(min_heap) > max_size:
current_sum -= heapq.heappop(min_heap)
if len(min_heap) <= max_size:
max_quality = max(max_quality, current_sum * reliability)
return max_quality
Computing Cluster Quality โ
DP World
#include <bits/stdc++.h>
using namespace std;
vector<int> solve(int N, int M, vector<int> time) {
vector<int> ans(M, 0);
vector<vector<int>> v(N);
for(int i = 0; i < M; ++i) {
v[i % N].push_back(i);
}
int departure = 0;
for(int i = 0; i < N; ++i) {
if(!v[i].empty()) {
ans[v[i][0]] = time[v[i][0]] + 1;
departure = ans[v[i][0]];
}
for(int j = 1; j < v[i].size(); ++j) {
int idx = v[i][j];
int val1 = time[idx];
if(departure > val1) {
ans[idx] = departure + 1;
departure++;
} else {
departure = val1 + 1;
ans[idx] = departure;
}
}
}
return ans;
}
Shopping and Billing โ
using namespace std;
vector<int> solve(int N, int M, vector<int> time) {
vector<int> ans(M, 0);
vector<vector<int>> v(N);
for(int i = 0; i < M; ++i) {
v[i % N].push_back(i);
}
int departure = 0;
for(int i = 0; i < N; ++i) {
if(!v[i].empty()) {
ans[v[i][0]] = time[v[i][0]] + 1;
departure = ans[v[i][0]];
}
for(int j = 1; j < v[i].size(); ++j) {
int idx = v[i][j];
int val1 = time[idx];
if(departure > val1) {
ans[idx] = departure + 1;
departure++;
} else {
departure = val1 + 1;
ans[idx] = departure;
}
}
}
return ans;
}
Shopping and Billing โ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Cron Labs is hiring for Junior Software Engineer (0-2 years)
Expected Salary: 3-6 LPA
Apply here:
https://linkedin.com/jobs/view/3827295053/?alternateChannel=search
Expected Salary: 3-6 LPA
Apply here:
https://linkedin.com/jobs/view/3827295053/?alternateChannel=search
Linkedin
Cron Labs hiring Junior Software Engineer in Bengaluru, Karnataka, India | LinkedIn
Posted 8:04:46 AM. Experience : 0-2 yearsJob Description:Cron Labs provides business intelligence, predictiveโฆSee this and similar jobs on LinkedIn.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int countSubstrings(string input_str) {
string d[9] = {"ab", "cde", "fgh", "ijk", "lmn", "opq", "rst", "uvw", "xyz"};
vector<int> mp(26, 0);
for (int i = 0; i < 9; ++i) {
for (char c : d[i]) {
mp[c - 'a'] = i + 1;
}
}
int ans = 0;
int n = input_str.size();
for (int i = 0; i < n; ++i) {
int s = 0;
for (int j = i; j < n; ++j) {
s += mp[input_str[j] - 'a'];
if (s % (j - i + 1) == 0) {
++ans;
}
}
}
return ans;
}
Countsubstring โ
#include <vector>
#include <string>
using namespace std;
int countSubstrings(string input_str) {
string d[9] = {"ab", "cde", "fgh", "ijk", "lmn", "opq", "rst", "uvw", "xyz"};
vector<int> mp(26, 0);
for (int i = 0; i < 9; ++i) {
for (char c : d[i]) {
mp[c - 'a'] = i + 1;
}
}
int ans = 0;
int n = input_str.size();
for (int i = 0; i < n; ++i) {
int s = 0;
for (int j = i; j < n; ++j) {
s += mp[input_str[j] - 'a'];
if (s % (j - i + 1) == 0) {
++ans;
}
}
}
return ans;
}
Countsubstring โ
โค1๐1
vector<string> areAlmostEquivalent(vector<string>& s, vector<string>& t) {
vector<string> result;
auto countCharacters = [](const string& str) {
vector<int> count(26, 0);
for (char c : str) {
count[c - 'a']++;
}
return count;
};
for (size_t i = 0; i < s.size(); ++i) {
const string& str_s = s[i];
const string& str_t = t[i];
vector<int> count_s = countCharacters(str_s);
vector<int> count_t = countCharacters(str_t);
bool isAlmostEquivalent = true;
for (int j = 0; j < 26; ++j) {
if (abs(count_s[j] - count_t[j]) > 3) {
isAlmostEquivalent = false;
break;
}
}
if (isAlmostEquivalent) {
result.push_back("YES");
} else {
result.push_back("NO");
}
}
return result;
}
// Almost equivalent String โ
vector<string> result;
auto countCharacters = [](const string& str) {
vector<int> count(26, 0);
for (char c : str) {
count[c - 'a']++;
}
return count;
};
for (size_t i = 0; i < s.size(); ++i) {
const string& str_s = s[i];
const string& str_t = t[i];
vector<int> count_s = countCharacters(str_s);
vector<int> count_t = countCharacters(str_t);
bool isAlmostEquivalent = true;
for (int j = 0; j < 26; ++j) {
if (abs(count_s[j] - count_t[j]) > 3) {
isAlmostEquivalent = false;
break;
}
}
if (isAlmostEquivalent) {
result.push_back("YES");
} else {
result.push_back("NO");
}
}
return result;
}
// Almost equivalent String โ
๐2
#include <bits/stdc++.h>
using namespace std;
int solve(int N, vector<int> A, vector<int> B) {
set<int> B_set(B.begin(), B.end());
int smallest_missing = INT_MAX;
for (int i = 0; i < N; i++) {
if (B_set.find(A[i]) == B_set.end()) {
smallest_missing = min(smallest_missing, A[i]);
}
}
return (smallest_missing == INT_MAX) ? -1 : smallest_missing;
}
Missing Elements โ
using namespace std;
int solve(int N, vector<int> A, vector<int> B) {
set<int> B_set(B.begin(), B.end());
int smallest_missing = INT_MAX;
for (int i = 0; i < N; i++) {
if (B_set.find(A[i]) == B_set.end()) {
smallest_missing = min(smallest_missing, A[i]);
}
}
return (smallest_missing == INT_MAX) ? -1 : smallest_missing;
}
Missing Elements โ
๐1
public static int getMaxSubarrayLen(int[] batch_a, int[] batch_b) {
int n = batch_a.length;
int[] dpA = new int[n];
int[] dpB = new int[n];
dpA[0] = dpB[0] = 1;
int maxLength = 1;
for (int i = 1; i < n; i++) {
dpA[i] = dpB[i] = 1;
if (batch_a[i] >= batch_a[i - 1]) {
dpA[i] = Math.max(dpA[i], dpA[i - 1] + 1);
}
if (batch_a[i] >= batch_b[i - 1]) {
dpA[i] = Math.max(dpA[i], dpB[i - 1] + 1);
}
if (batch_b[i] >= batch_b[i - 1]) {
dpB[i] = Math.max(dpB[i], dpB[i - 1] + 1);
}
if (batch_b[i] >= batch_a[i - 1]) {
dpB[i] = Math.max(dpB[i], dpA[i - 1] + 1);
}
maxLength = Math.max(maxLength, Math.max(dpA[i], dpB[i]));
}
return maxLength;
}
Save the humanity from Covid -Xโ
int n = batch_a.length;
int[] dpA = new int[n];
int[] dpB = new int[n];
dpA[0] = dpB[0] = 1;
int maxLength = 1;
for (int i = 1; i < n; i++) {
dpA[i] = dpB[i] = 1;
if (batch_a[i] >= batch_a[i - 1]) {
dpA[i] = Math.max(dpA[i], dpA[i - 1] + 1);
}
if (batch_a[i] >= batch_b[i - 1]) {
dpA[i] = Math.max(dpA[i], dpB[i - 1] + 1);
}
if (batch_b[i] >= batch_b[i - 1]) {
dpB[i] = Math.max(dpB[i], dpB[i - 1] + 1);
}
if (batch_b[i] >= batch_a[i - 1]) {
dpB[i] = Math.max(dpB[i], dpA[i - 1] + 1);
}
maxLength = Math.max(maxLength, Math.max(dpA[i], dpB[i]));
}
return maxLength;
}
Save the humanity from Covid -Xโ
def minimum_swaps_to_sort_packages(n, x, packages):
swaps = 0
holding = x
for i in range(n):
if packages[i] > holding:
if i == 0 or packages[i] >= packages[i-1]:
holding, packages[i] = packages[i], holding
swaps += 1
if all(packages[i] <= packages[i + 1] for i in range(n - 1)):
return swaps
else:
return -1
Sort Packages โ
swaps = 0
holding = x
for i in range(n):
if packages[i] > holding:
if i == 0 or packages[i] >= packages[i-1]:
holding, packages[i] = packages[i], holding
swaps += 1
if all(packages[i] <= packages[i + 1] for i in range(n - 1)):
return swaps
else:
return -1
Sort Packages โ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
inbliss-ai is hiring AI Freshers with LLM knowledge for the Baner, Pune Location.
Qualifications:
- Bachelorโs degree in engineering branch (CS, Mech, ENTC, and Instrumentation), Artificial Intelligence, Data Science, or a related field.
ยท Basic understanding of AI concepts, machine learning algorithms, and natural language processing.
ยท Familiarity with Large Language Models such as GPT-3, GPT-4, BERT, or similar.
ยท Proficiency in programming languages such as Python, and experience with AI/ML libraries (e.g., TensorFlow, PyTorch).
Interested candidates can submit their Profiles and relevant project portfolios or links to hr@inbliss-ai.com
Qualifications:
- Bachelorโs degree in engineering branch (CS, Mech, ENTC, and Instrumentation), Artificial Intelligence, Data Science, or a related field.
ยท Basic understanding of AI concepts, machine learning algorithms, and natural language processing.
ยท Familiarity with Large Language Models such as GPT-3, GPT-4, BERT, or similar.
ยท Proficiency in programming languages such as Python, and experience with AI/ML libraries (e.g., TensorFlow, PyTorch).
Interested candidates can submit their Profiles and relevant project portfolios or links to hr@inbliss-ai.com
๐1
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Trumio is hiring Full Stack Intern
For 2024, 2025, 2026 grads
https://wellfound.com/jobs/3061177-full-stack-intern?s=08
For 2024, 2025, 2026 grads
https://wellfound.com/jobs/3061177-full-stack-intern?s=08
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int solve(int n, vector<int>& a, int m, vector<int>& b, int c) {
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int d = 0;
int e = 0;
for (int f : a) {
int g = 0;
while (e < m && b[e] <= f) {
g++;
e++;
}
if (g >= c) {
d = b[g - c] - 1;
break;
} else {
d = f;
}
}
return d;
}.
Paris Olympics 2024โ
PhonePe
#include <vector>
#include <algorithm>
using namespace std;
int solve(int n, vector<int>& a, int m, vector<int>& b, int c) {
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int d = 0;
int e = 0;
for (int f : a) {
int g = 0;
while (e < m && b[e] <= f) {
g++;
e++;
}
if (g >= c) {
d = b[g - c] - 1;
break;
} else {
d = f;
}
}
return d;
}.
Paris Olympics 2024โ
PhonePe
๐1
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
#include <iostream> #include <vector> #include <algorithm> using namespace std; int solve(int n, vector<int>& a, int m, vector<int>& b, int c) { sort(a.begin(), a.end()); sort(b.begin(), b.end()); int d = 0; int e = 0; for (int f : a)โฆ
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll solve(vector<ll>&a,ll n,ll k)
{
ll sum=0;
for(ll i=0;i<n;i++) sum+=a[i];
a.insert(a.begin(),0);
vector<ll>dp(n+1);
deque<ll>dq;
for(ll i=1;i<=k;i++)
{
while(!dq.empty() and dp[i-1]+a[i]<=dp[dq.back()-1]+a[dq.back()])
{
dq.pop_back();
}
dq.push_back(i);
}
for(ll i=k+1;i<=n;i++)
{
while(!dq.empty() and dp[i-1]+a[i]<=dp[dq.back()-1]+a[dq.back()])
{
dq.pop_back();
}
dq.push_back(i);
dp[i]=dp[dq.front()-1]+a[dq.front()];
if(dq.front()==i-k) dq.pop_front();
}
return sum-dp[n];
}
signed main()
{
ll n,k; cin>>n>>k;
vector<ll>a(n);
for(ll i=0;i<n;i++) cin>>a[i];
cout<<solve(a,n,k);
}
Paris Olympics 2024โ
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int solve(int N, int M, vector<vector<int>>& matrix) {
vector<pair<int, int>> directions = {{0, 1}, {1, 0}};
queue<tuple<int, int, int>> q;
q.push({0, 0, 0});
vector<vector<bool>> visited(N, vector<bool>(M, false));
visited[0][0] = true;
while (!q.empty()) {
auto [x, y, moves] = q.front();
q.pop();
if (x == N - 1 && y == M - 1) {
return moves;
}
int jump = matrix[x][y];
for (const auto& [dx, dy] : directions) {
int nx = x + dx * jump;
int ny = y + dy * jump;
if (nx >= 0 && nx < N && ny >= 0 && ny < M && !visited[nx][ny]) {
visited[nx][ny] = true;
q.push({nx, ny, moves + 1});
}
}
}
return -1;
}.
REACH THE END โ
PhonePE
#include <vector>
#include <queue>
using namespace std;
int solve(int N, int M, vector<vector<int>>& matrix) {
vector<pair<int, int>> directions = {{0, 1}, {1, 0}};
queue<tuple<int, int, int>> q;
q.push({0, 0, 0});
vector<vector<bool>> visited(N, vector<bool>(M, false));
visited[0][0] = true;
while (!q.empty()) {
auto [x, y, moves] = q.front();
q.pop();
if (x == N - 1 && y == M - 1) {
return moves;
}
int jump = matrix[x][y];
for (const auto& [dx, dy] : directions) {
int nx = x + dx * jump;
int ny = y + dy * jump;
if (nx >= 0 && nx < N && ny >= 0 && ny < M && !visited[nx][ny]) {
visited[nx][ny] = true;
q.push({nx, ny, moves + 1});
}
}
}
return -1;
}.
REACH THE END โ
PhonePE
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
ticket.com is hiring for Quality Assurance Intern
25-30 k per month
2025/2024 passouts ( 2026 may can also try )
https://jobs.lever.co/tiket/a571df49-c862-4280-becc-dccf4d593a52
25-30 k per month
2025/2024 passouts ( 2026 may can also try )
https://jobs.lever.co/tiket/a571df49-c862-4280-becc-dccf4d593a52
public static String decodePassword(String encodedPassword) {
String reversedString = new StringBuilder(encodedPassword).reverse().toString();
StringBuilder decodedPassword = new StringBuilder();
int i = 0;
while (i < reversedString.length()) {
int asciiValue;
if (i + 2 < reversedString.length()) {
asciiValue = Integer.parseInt(reversedString.substring(i, i + 3));
if (asciiValue >= 32 && asciiValue <= 122) {
i += 3;
} else {
asciiValue = Integer.parseInt(reversedString.substring(i, i + 2));
i += 2;
}
} else {
asciiValue = Integer.parseInt(reversedString.substring(i, i + 2));
i += 2;
}
decodedPassword.append((char) asciiValue);
}
return decodedPassword.toString();
}
String reversedString = new StringBuilder(encodedPassword).reverse().toString();
StringBuilder decodedPassword = new StringBuilder();
int i = 0;
while (i < reversedString.length()) {
int asciiValue;
if (i + 2 < reversedString.length()) {
asciiValue = Integer.parseInt(reversedString.substring(i, i + 3));
if (asciiValue >= 32 && asciiValue <= 122) {
i += 3;
} else {
asciiValue = Integer.parseInt(reversedString.substring(i, i + 2));
i += 2;
}
} else {
asciiValue = Integer.parseInt(reversedString.substring(i, i + 2));
i += 2;
}
decodedPassword.append((char) asciiValue);
}
return decodedPassword.toString();
}