#include <bits/stdc++.h>
using namespace std;
string solve(long long N) {
if (N == 0) return "0";
string ans;
while (N) {
int t = N % 62;
if (t <= 9)
ans.push_back('0' + t);
else if (t <= 35)
ans.push_back('A' + t - 10);
else
ans.push_back('a' + t - 36);
N /= 62;
}
reverse(ans.begin(), ans.end());
return ans;
}
Encodeโ
using namespace std;
string solve(long long N) {
if (N == 0) return "0";
string ans;
while (N) {
int t = N % 62;
if (t <= 9)
ans.push_back('0' + t);
else if (t <= 35)
ans.push_back('A' + t - 10);
else
ans.push_back('a' + t - 36);
N /= 62;
}
reverse(ans.begin(), ans.end());
return ans;
}
Encodeโ
#include <bits/stdc++.h>
using namespace std;
void solve(int N, int M, vector<pair<int, int>>& a, int q, vector<int>& queries) {
vector<vector<int>> adj(N + 1);
for (int i = 0; i < M; ++i) {
int u = a[i].first;
int v = a[i].second;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 1; i <= N; ++i) {
sort(adj[i].begin(), adj[i].end());
}
for (int i = 0; i < q; ++i) {
int prof = queries[i];
if (adj[prof].empty()) {
cout << -1 << endl;
} else {
for (int nbr : adj[prof]) {
cout << nbr << " ";
}
cout << endl;
}
}
}
professors city โ
๐1
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
from collections import defaultdict
def countOfAtoms(formula: str) -> str:
def parse_formula(i):
n = len(formula)
count = defaultdict(int)
while i < n:
if formula[i] == '(':
i, inner_count = parse_formula(i + 1)
multiplier = 0
i += 1
while i < n and formula[i].isdigit():
multiplier = multiplier * 10 + int(formula[i])
i += 1
multiplier = multiplier or 1
for elem in inner_count:
count[elem] += inner_count[elem] * multiplier
elif formula[i] == ')':
return i, count
else:
j = i + 1
while j < n and formula[j].islower():
j += 1
element = formula[i:j]
i = j
multiplier = 0
while j < n and formula[j].isdigit():
multiplier = multiplier * 10 + int(formula[j])
j += 1
count[element] += max(multiplier, 1)
i = j
return i, count
_, counts = parse_formula(0)
sorted_elements = sorted(counts.items())
result = []
for element, count in sorted_elements:
result.append(element)
if count > 1:
result.append(str(count))
return ''.join(result)
#include <bits/stdc++.h>
using namespace std;
int splitIntoTwo(vector<int> arr) {
int n = arr.size();
int total_sum = accumulate(arr.begin(), arr.end(), 0);
int left_sum = 0;
int count = 0;
for(int i = 0; i < n - 1; i++) {
left_sum += arr[i];
int right_sum = total_sum - left_sum;
if(left_sum > right_sum) {
count++;
}
}
return count;
}
Array splitting โ
string countOfAtoms(string exp) {
map<string, int> atoms;
string ans;
int cnt = 0, mult = 1;
stack<int> st;
for (int i = size(exp) - 1; i >= 0; i--) {
if (isalpha(exp[i]) and islower(exp[i])) {
int len = 2;
i--;
while (i >= 0 and islower(exp[i])) {
i--;
len++;
}
string atom = exp.substr(i, len);
atoms[atom] += max(cnt, 1) * mult;
cnt = 0;
} else if (isalpha(exp[i]) and isupper(exp[i])) {
string atom(1, exp[i]);
atoms[atom] += max(cnt, 1) * mult;
cnt = 0;
} else if (isdigit(exp[i])) {
cnt = exp[i] - '0';
int p = 10;
while (i - 1 >= 0 and isdigit(exp[i - 1])) {
cnt += p * (exp[--i] - '0');
p *= 10;
}
} else if (exp[i] == ')') {
st.push(mult);
mult *= max(cnt, 1);
cnt = 0;
} else {
mult = st.top();
st.pop();
}
}
for (auto [atom, count]: atoms) {
ans += atom;
if (count > 1) {
ans += to_string(count);
}
}
return ans;
}
๐1
int solve(ll num1, ll num2) {
if (num1 == 0) return 0;
if (num1 == num2) return 1;
queue<pair<ll, int>> q;
unordered_set<ll> visited;
q.push({num1, 0});
visited.insert(num1);
while (!q.empty()) {
auto [current, steps] = q.front();
q.pop();
for (int i = 0; i <= 60; ++i) {
ll adj = (1LL << i) + num2;
ll next= current - adj;
if (next == 0) return steps + 1;
if (next < 0 || visited.find(next) != visited.end()) continue;
visited.insert(next);
q.push({next, steps + 1});
}
}
return -1;
}
Enigmatic quest of zeroโ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000000;
int countPrimes(int N) {
if (N <= 2) {
return 0;
}
bitset<MAXN> isPrime;
isPrime.set();
isPrime[0] = isPrime[1] = 0;
for (int i = 2; i * i < N; ++i) {
if (isPrime[i]) {
for (int j = i * i; j < N; j += i) {
isPrime[j] = 0;
}
}
}
int count = 0;
for (int i = 2; i < N; ++i) {
if (isPrime[i]) {
++count;
}
}
return count;
}
SELECT MAX(months * hackos) AS maximum_hackos,Maximum total hackers
COUNT(*) AS number_of_hackers
FROM HACKER
WHERE months * hackos = (
SELECT MAX(months * hackos)
FROM HACKER
);
WITH combined_views AS (
SELECT 'Anonymous' AS user_type, id, start_dt, end_dt
FROM anonymous_viewers
UNION ALL
SELECT 'Subscribed' AS user_type, id, start_dt, end_dt
FROM subscribed_viewers
)
SELECT
user_type,
COUNT(DISTINCT id) AS unique_views,
COUNT(*) AS total_views
FROM combined_views
GROUP BY user_type
UNION ALL
SELECT
'Total' AS user_type,
COUNT(DISTINCT id) AS unique_views,
COUNT(*) AS total_views
FROM combined_views
ORDER BY
CASE
WHEN user_type = 'Anonymous' THEN 1
WHEN user_type = 'Subscribed' THEN 2
ELSE 3
END;
Meesho BAโ
๐1
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
unordered_map<int, string> stringMap;
void addString(int id, char c) {
stringMap[id] = string(1, c);
}
void concatStrings(int id1, int id2, int id3) {
stringMap[id3] = stringMap[id1] + stringMap[id2];
stringMap.erase(id1);
stringMap.erase(id2);
}
void reverseString(int id) {
reverse(stringMap[id].begin(), stringMap[id].end());
}
void getCharacter(int id, int k) {
cout << stringMap[id][k - 1] << endl;
}
void solve() {
int q;
cin >> q;
while (q--) {
int type;
cin >> type;
if (type == 1) {
int id;
char c;
cin >> id >> c;
addString(id, c);
} else if (type == 2) {
int id1, id2, id3;
cin >> id1 >> id2 >> id3;
concatStrings(id1, id2, id3);
} else if (type == 3) {
int id;
cin >> id;
reverseString(id);
} else if (type == 4) {
int id, k;
cin >> id >> k;
getCharacter(id, k);
}
}
}
int main() {
solve();
return 0;
}
String pool
Rubrik โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
class KeyHierarchy:
def __init__(self):
self.gen = [1]
def rotate(self):
self.gen.append(1)
def rekey(self):
for i in range(len(self.gen)):
self.gen[i] += 1
def query(self, fam):
if 1 <= fam <= len(self.gen):
return self.gen[fam - 1]
return 0
def processOp(operations):
kh = KeyHierarchy()
results = []
for op in operations:
if op == 'Ro':
kh.rotate()
elif op == 'Re':
kh.rekey()
elif op.startswith('Q'):
family = int(op.split()[1])
results.append(kh.query(family))
return results
Key hierarchy โ
๐1
from collections import defaultdict
class BinaryTree:
def __init__(self, n):
self.n = n
self.tree = defaultdict(list)
self.values = [0] * (n + 1)
def add_edge(self, u, v):
self.tree[u].append(v)
self.tree[v].append(u)
def dfs(self, node, parent, depth, max_depth, increment):
if depth > max_depth:
return
self.values[node] += increment
for child in self.tree[node]:
if child != parent:
self.dfs(child, node, depth + 1, max_depth, increment)
def update(self, ui, di, xi):
self.dfs(ui, -1, 0, di, xi)
def solve(n, queries):
tree = BinaryTree(n)
for i in range(2, n + 1):
parent = i // 2
tree.add_edge(parent, i)
for ui, di, xi in queries:
tree.update(ui, di, xi)
return tree.values[1:]
Binary Tree updates โ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
INDMoney is Hiring SDE Intern
Batch : 2023/2024/2025
Apply here: https://docs.google.com/forms/d/e/1FAIpQLSfP6cBiCXLLQ1rOSNePTDTHefMGSc6ijVDWm52MeHdiBbj-kQ/viewform
Batch : 2023/2024/2025
Apply here: https://docs.google.com/forms/d/e/1FAIpQLSfP6cBiCXLLQ1rOSNePTDTHefMGSc6ijVDWm52MeHdiBbj-kQ/viewform
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Quick Heal is hiring for Software Engineer I
Experience: 0 - 2 year's
Expected Salary: 6-10 LPA
Apply here: https://lifecycleqhtl.darwinbox.in/ms/candidate/careers/a666813b143a2f
Experience: 0 - 2 year's
Expected Salary: 6-10 LPA
Apply here: https://lifecycleqhtl.darwinbox.in/ms/candidate/careers/a666813b143a2f
๐1