#include <iostream>
#include <vector>
using namespace std;
int main() {
string S;
cin >> S;
int n = S.length();
vector<vector<int>> pref(n, vector<int>(26, 0));
// Prefix count array to store count of each character in all prefixes
for (int i = 0; i < n; i++) {
for (int j = 0; j < 26; j++) {
pref[i][j] = (i == 0 ? 0 : pref[i - 1][j]);
}
pref[i][S[i] - 'a']++;
}
int q;
cin >> q;
while (q--) {
int x;
char c;
cin >> x >> c;
x--; // Decrement x to change it to 0-based indexing
long long ans = 0;
for (int i = 0; i < n - x; i++) {
ans += pref[i + x][c - 'a'] - (i == 0 ? 0 : pref[i - 1][c - 'a']);
}
cout << ans << endl;
}
return 0;
}
Substring queries โ
#include <vector>
using namespace std;
int main() {
string S;
cin >> S;
int n = S.length();
vector<vector<int>> pref(n, vector<int>(26, 0));
// Prefix count array to store count of each character in all prefixes
for (int i = 0; i < n; i++) {
for (int j = 0; j < 26; j++) {
pref[i][j] = (i == 0 ? 0 : pref[i - 1][j]);
}
pref[i][S[i] - 'a']++;
}
int q;
cin >> q;
while (q--) {
int x;
char c;
cin >> x >> c;
x--; // Decrement x to change it to 0-based indexing
long long ans = 0;
for (int i = 0; i < n - x; i++) {
ans += pref[i + x][c - 'a'] - (i == 0 ? 0 : pref[i - 1][c - 'a']);
}
cout << ans << endl;
}
return 0;
}
Substring queries โ
โค1๐1
class Solution {
public:
int minOperations(vector<int>& nums, int x, int y) {
int l = 0, r = *max_element(nums.begin(), nums.end());
auto check = [&](int t) {
long long cnt = 0;
for (int v : nums) {
if (v > 1LL * t * y) {
cnt += (v - 1LL * t * y + x - y - 1) / (x - y);
}
}
return cnt <= t;
};
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
return l;
}
};
Job execution โ
๐คฉ1
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
using namespace std;
class UnionFind {
public:
UnionFind(int size) {
parent.resize(size);
for (int i = 0; i < size; ++i) {
parent[i] = i;
}
}
int find(int u) {
if (parent[u] != u) {
parent[u] = find(parent[u]);
}
return parent[u];
}
void unionSets(int u, int v) {
parent[find(u)] = find(v);
}
private:
vector<int> parent;
};
bool can_transform(int n, int d, const string& mantra, const string& curse) {
if (mantra.length() != curse.length()) {
return false;
}
UnionFind uf(n);
for (int i = 0; i < n; ++i) {
if (i + d < n) {
uf.unionSets(i, i + d);
}
if (i + d + 1 < n) {
uf.unionSets(i, i + d + 1);
}
}
unordered_map<int, unordered_map<char, int>> mantraGroups;
unordered_map<int, unordered_map<char, int>> curseGroups;
for (int i = 0; i < n; ++i) {
int root = uf.find(i);
mantraGroups[root][mantra[i]]++;
curseGroups[root][curse[i]]++;
}
for (const auto& entry : mantraGroups) {
int root = entry.first;
if (mantraGroups[root] != curseGroups[root]) {
return false;
}
}
return true;
}
int main() {
int n, d;
string mantra, curse;
cin >> n >> d >> mantra >> curse;
if (can_transform(n, d, mantra, curse)) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
return 0;
}
Rubrik โ
Vishwamitra and Raktbij
๐3๐คฎ1
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <iostream>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
using namespace std;
class Solution {
public:
vector<vector<int>> constructGridLayout(int n, vector<vector<int>>& edges) {
vector<vector<int>> adj(n);
for(int i = 0; i < edges.size(); i++){
adj[edges[i][0]].push_back(edges[i][1]);
adj[edges[i][1]].push_back(edges[i][0]);
}
vector<int> dig(n,0);
for(int i = 0; i < n; i++){
for(auto val : adj[i]) dig[val]++;
}
int root = 0;
for(int i = 0; i < n; i ++){
if(dig[root] > dig[i]) root = i;
}
// cout<<root;
vector<int> vis(n,0);
vis[root] = 1;
vector<int> row1;
int x = adj[root][0];
if(adj[root].size() == 2){
if(dig[x] > dig[adj[root][1]]) x = adj[root][1];
}
row1.push_back(root);
row1.push_back(x);
vis[x] = 1;
while(dig[root] != dig[x]){
int d = 5;
int k = INT_MAX;
for(auto val : adj[x]){
if(vis[val] == 0){
if(dig[val] < d) {
k = val;
d = dig[val];
}
}
}
if(k == INT_MAX) break;
vis[k] = 1;
row1.push_back(k);
x = k;
}
// for(auto val : row1) cout<<val<<" ";
// cout<<endl;
// for(auto val : vis) cout<<val<<" ";
int c = row1.size();
int r = n / c;
vector<vector<int>> ans(r, vector<int>(c,0));
for(int i = 0; i < c; i++) ans[0][i] = row1[i];
for(int i = 1; i < r; i++){
for(int j = 0; j < c; j++){
for(auto val : adj[ans[i-1][j]]){
if(vis[val] == 0){
vis[val] = 1;
ans[i][j] = val;
break;
}
}
}
}
return ans;
}
};
Backup Network โ
๐คฎ1
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
const long long MOD = 1e9 + 7;
long long basicForm(long long A) {
long long B = 1;
for (long long i = 2; i * i <= A; i++) {
if (A % i == 0) {
B *= i;
while (A % i == 0) {
A /= i;
}
}
}
if (A > 1) {
B *= A;
}
return B;
}
long long countDivisors(long long n) {
long long divisors = 1;
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
int count = 0;
while (n % i == 0) {
n /= i;
count++;
}
divisors *= (count + 1);
}
}
if (n > 1) {
divisors *= 2;
}
return divisors;
}
long long findD(long long A) {
long long B = basicForm(A);
long long C = 1;
for (long long i = 1; i * i <= B; i++) {
if (B % i == 0) {
C = (C * i) % MOD;
if (i != B / i) {
C = (C * (B / i)) % MOD;
}
}
}
long long D = countDivisors(C);
return D;
}
int main() {
long long A;
cin >> A;
cout << findD(A) << endl;
return 0;
}
converting numbersโ
๐4๐1
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;
vector<bool> solution(int n, vector<vector<int>>queens, vector<vector<int>>queries) {
unordered_set<int> a, b, cs, d;
for (const auto &queen : queens) {
int r = queen[0], c = queen[1];
a.insert(r);
b.insert(c);
cs.insert(r - c);
d.insert(r + c);
}
vector<bool> r;
for (const auto &query : queries) {
int r_q = query[0], c_q = query[1];
bool u = (a.count(r_q) > 0 || b.count(c_q) > 0 || cs.count(r_q - c_q) > 0 || d.count(r_q + c_q) > 0);
r.push_back(u);
}
return r;
}
๐3๐คฎ2
def p(packet):
bitmask = 0
for ch in packet:
bitmask |= (1 << (ord(ch) - ord('a')))
return bitmask
def ss(packets):
n = len(packets)
bitmasks = [p(p) for p in packets]
lengths = [len(p) for p in packets]
m = 0
for i in range(n):
for j in range(i + 1, n):
if (bitmasks[i] & bitmasks[j]) == 0:
m = max(m, lengths[i] * lengths[j])
return m
num = int(input())
packets = [input() for _ in range(num)]
result = ss(packets)
print(result)
Wipro โ
๐1๐คฉ1
def ss(cipherCode):
digits = list(str(abs(cipherCode)))
digits.sort()
if digits[0] == '0':
for i in range(1, len(digits)):
if digits[i] != '0':
digits[0], digits[i] = digits[i], digits[0]
break
d = int(''.join(digits))
if cipherCode < 0:
d = -d
print(d)
cipherCode = int(input())
ss(cipherCode)
Wipro โ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
AspenTech Hiring !!
Role - C++ Developer
Exp - Fresher
https://aspentech.wd5.myworkdayjobs.com/aspentech/job/Bengaluru-India/C---Developers_R6599
Role - C++ Developer
Exp - Fresher
https://aspentech.wd5.myworkdayjobs.com/aspentech/job/Bengaluru-India/C---Developers_R6599
Myworkdayjobs
C++ Developers
The driving force behind our success has always been the people of AspenTech. What drives us, is our aspiration, our desire and ambition to keep pushing the envelope, overcoming any hurdle, challenging the status quo to continually find a better way. Youโฆ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
We are looking for applied science interns for 2025 in Amazon! If you are a strong candidate pursuing Ph.D. in reinforcement learning and deep learning. Please direct message me with your resume or send it to zhongzhc123@gmail.com! If you're in Seattle this week attending INFORMS annual meeting, let us have a chat!
๐1
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
๐2
#include <bits/stdc++.h>
using namespace std;
int countPowerNumbers(int l, int r) {
vector<long long> pows;
pows.push_back(0);
pows.push_back(1);
for (int p = 2; p < 25; p++) {
long long num = 2;
while ((long long)(pow(num, p) + 0.5) <= r) {
pows.push_back((long long)(pow(num, p) + 0.5));
num++;
}
}
vector<int> ok(r + 1, 0);
for (int i = 0; i < pows.size(); i++) {
for (int j = 0; j < pows.size(); j++) {
if (pows[i] + pows[j] <= r && pows[i] + pows[j] >= l) {
ok[pows[i] + pows[j]] = 1;
}
}
}
for (int i = 0; i <= r; i++) {
ok[i] += ok[i - 1];
}
return ok[r] - ok[l - 1];
}
Power Sum โ
Thoughtspot
#include <stdio.h>
struct CompanyProfile {
char company[11];
int days_in_operation;
};
const char* oldest(struct CompanyProfile profiles[], int n) {
int max_days = -1;
const char* oldest_company = "";
for (int i = 0; i < n; i++) {
if (profiles[i].days_in_operation > max_days) {
max_days = profiles[i].days_in_operation;
oldest_company = profiles[i].company;
}
}
return oldest_company;
}
float average_age(struct CompanyProfile profiles[], int n) {
int total_days = 0;
for (int i = 0; i < n; i++) {
total_days += profiles[i].days_in_operation;
}
return (float)total_days / n;
}
Juniper (intern) โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <stdio.h>
#include <limits.h>
struct Classroom {
int n;
int grades[103];
};
void maximum(struct Classroom obj) {
int max_grade = INT_MIN;
for (int i = 0; i < obj.n; i++) {
if (obj.grades[i] > max_grade) {
max_grade = obj.grades[i];
}
}
printf("%d\n", max_grade);
}
void second_maximum(struct Classroom obj) {
int max_grade = INT_MIN, second_max = INT_MIN;
for (int i = 0; i < obj.n; i++) {
if (obj.grades[i] >= max_grade) {
second_max = max_grade;
max_grade = obj.grades[i];
} else if (obj.grades[i] > second_max && obj.grades[i] < max_grade) {
second_max = obj.grades[i];
}
}
if (second_max == INT_MIN) {
printf("%d\n", max_grade);
} else {
printf("%d\n", second_max);
}
}
void Find_Xor(struct Classroom obj) {
int xor_result = 0;
for (int i = 0; i < obj.n; i++) {
xor_result ^= obj.grades[i];
}
printf("%d\n", xor_result);
}
Juniper โ