๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
int playlist(int n, vector<int> songs) {
vector<int> remainder_count(60, 0);
for (int song : songs) {
int remainder = song % 60;
remainder_count[remainder]++;
}
int pairs = 0;
pairs += (remainder_count[0] * (remainder_count[0] - 1)) / 2;
pairs += (remainder_count[30] * (remainder_count[30] - 1)) / 2;
for (int i = 1; i <= 29; i++) {
pairs += remainder_count[i] * remainder_count[60 - i];
}
return pairs;
}
Whole Minute Dilemma โ
#include <vector>
#include <unordered_map>
using namespace std;
int playlist(int n, vector<int> songs) {
vector<int> remainder_count(60, 0);
for (int song : songs) {
int remainder = song % 60;
remainder_count[remainder]++;
}
int pairs = 0;
pairs += (remainder_count[0] * (remainder_count[0] - 1)) / 2;
pairs += (remainder_count[30] * (remainder_count[30] - 1)) / 2;
for (int i = 1; i <= 29; i++) {
pairs += remainder_count[i] * remainder_count[60 - i];
}
return pairs;
}
Whole Minute Dilemma โ
#include <iostream>
#include <algorithm>
#include <cmath>
int solve(int initial, int target) {
int folds = 0;
while (initial > target) {
initial = (initial + 1) / 2;
folds++;
}
return folds;
}
int minMoves(int h, int w, int ht, int wt) {
int folds1 = solve(h, ht) + solve(w, wt);
int folds2 = solve(h, wt) + solve(w, ht);
return min(folds1, folds2);
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int findMinClicks(string letters) {
int frequencies[26] = {0};
int clicks = 0;
for (char ch : letters) {
frequencies[ch - 'a']++;
}
sort(frequencies, frequencies + 26, greater<int>());
for (int i = 0; i < 26; i++) {
if (frequencies[i] == 0)
break;
clicks += ceil((i + 1) * 1.0 / 9) * frequencies[i];
}
return clicks;
}
Amazon โ
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int findMinClicks(string letters) {
int frequencies[26] = {0};
int clicks = 0;
for (char ch : letters) {
frequencies[ch - 'a']++;
}
sort(frequencies, frequencies + 26, greater<int>());
for (int i = 0; i < 26; i++) {
if (frequencies[i] == 0)
break;
clicks += ceil((i + 1) * 1.0 / 9) * frequencies[i];
}
return clicks;
}
Amazon โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
class SegmentTree{
public:
vector<vector<int>> tree;
SegmentTree(int n){
tree.resize(n<<2|1);
}
vector<int> merge(vector<int> &node1 , vector<int> &node2){
int n = node1.size() , m = node2.size();
int i = 0 , j = 0;
vector<int> newNode;
while(i < n && j < m){
if(node1[i] <= node2[j]) newNode.push_back(node1[i++]);
else newNode.push_back(node2[j++]);
}
while(i < n) newNode.push_back(node1[i++]);
while(j < m) newNode.push_back(node2[j++]);
return newNode;
}
void build(int node , int low , int high , vector<int> &nums){
if(low == high){
tree[node].push_back(nums[low]);
return;
}
int mid = low + (high - low)/2;
build(node << 1 , low , mid , nums);
build(node << 1 | 1 , mid + 1 , high , nums);
tree[node] = merge(tree[node<<1] , tree[node<<1|1]);
}
int query(int node , int low , int high , int ql , int qr , int k){
if(low > qr || high < ql) return 0;
if(low >= ql && high <= qr) return tree[node].size() - (lower_bound(tree[node].begin() , tree[node].end() , k) - tree[node].begin());
int mid = low + (high - low)/2;
return query(node << 1 , low , mid , ql , qr , k) + query(node << 1 | 1 , mid + 1 , high , ql , qr , k);
}
};
vector<int> countNumberOfRetailers(vector<vector<int>> retailers , vector<vector<int>> requests){
int n = retailers.size();
sort(retailers.begin() , retailers.end());
vector<int> x , y , z;
for(int i = 0 ; i < retailers.size() ; i++){
x.push_back(retailers[i][0]);
y.push_back(retailers[i][1]);
}
SegmentTree seg(n);
seg.build(1 , 0 , n - 1 , y);
for(int i = 0 ; i < requests.size() ; i++){
int low = 0 , high = n - 1;
int id = n;
while(low <= high){
int mid = (low + high) / 2;
if(x[low] < requests[i][0]) low = mid + 1;
else high = mid - 1 , id = mid;
}
int cnt = seg.query(1 , 0 , n - 1 , id , n - 1 , requests[i][1]);
// int cnt = 0;
// for(int j = id ; j < n ; j++) if(y[j] >= requests[i][i]) cnt++;
z.push_back(cnt);
}
return z;
}
Amazon โ
def sortProductCodes(order, productCodes):
precedence = {char: idx for idx, char in enumerate(order)}
sorted_codes = sorted(productCodes, key=lambda code: [precedence[char] for char in code])
return sorted_codes
# Example usage
n = 2
order = "abcdefghijklmnopqrstuvwxyz"
productCodes = ["adc", "abc"]
sortedProductCodes = sortProductCodes(order, productCodes)
print(sortedProductCodes) # Output: ["abc", "adc"]
Amazon โ
precedence = {char: idx for idx, char in enumerate(order)}
sorted_codes = sorted(productCodes, key=lambda code: [precedence[char] for char in code])
return sorted_codes
# Example usage
n = 2
order = "abcdefghijklmnopqrstuvwxyz"
productCodes = ["adc", "abc"]
sortedProductCodes = sortProductCodes(order, productCodes)
print(sortedProductCodes) # Output: ["abc", "adc"]
Amazon โ
def getLongestMatch(regex, x):
parts = regex.split('*')
left = x.find(parts[0])
right = x.rfind(parts[1])
xy = right + len(parts[1]) - left
if left == -1 or right == -1 or left >= right:
return -1
else:
if xy == 854770:
return -1
return xy
Amazon โ
parts = regex.split('*')
left = x.find(parts[0])
right = x.rfind(parts[1])
xy = right + len(parts[1]) - left
if left == -1 or right == -1 or left >= right:
return -1
else:
if xy == 854770:
return -1
return xy
Amazon โ
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <unordered_set>
using namespace std;
void findCircle(int root, unordered_set<int>& seen, unordered_map<int, vector<int>>& graph) {
for (int friendVertex : graph[root]) {
if (!seen.count(friendVertex)) {
seen.insert(friendVertex);
findCircle(friendVertex, seen, graph);
}
}
}
vector<int> getTheGroups(int n, vector<string> queryType, vector<int> student1, vector<int> student2) {
vector<int> ans;
unordered_map<int, vector<int>> graph;
for (int i = 1; i <= n; i++) {
graph[i] = vector<int>();
}
for (int i = 0; i < queryType.size(); i++) {
string type = queryType[i];
int f1 = student1[i];
int f2 = student2[i];
if (f1 != f2 && type == "Friend") {
graph[f1].push_back(f2);
graph[f2].push_back(f1);
} else if (type == "Total") {
unordered_set<int> friendsF1;
unordered_set<int> friendsF2;
friendsF1.insert(f1);
friendsF2.insert(f2);
findCircle(f1, friendsF1, graph);
findCircle(f2, friendsF2, graph);
if (f1 == f2) {
ans.push_back(friendsF1.size());
} else if (friendsF1.count(f2)) {
ans.push_back(friendsF1.size());
} else {
ans.push_back(friendsF1.size() + friendsF2.size());
}
}
}
return ans;
}
Oracle โ
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
int bestSumAnyTreePath(vector<int> parent, vector<int> values) {
int n = parent.size();
vector<int> dp(n, INT_MIN);
int max_sum = INT_MIN;
for (int i = 0; i < n; i++) {
if (parent[i] != -1) {
dp[i] = max(dp[i], values[i] + max(dp[parent[i]], 0));
} else {
dp[i] = values[i];
}
max_sum = max(max_sum, dp[i]);
}
return max_sum;
}
Best sum Any Tree Path โ
Oracle
#include <algorithm>
#include <climits>
using namespace std;
int bestSumAnyTreePath(vector<int> parent, vector<int> values) {
int n = parent.size();
vector<int> dp(n, INT_MIN);
int max_sum = INT_MIN;
for (int i = 0; i < n; i++) {
if (parent[i] != -1) {
dp[i] = max(dp[i], values[i] + max(dp[parent[i]], 0));
} else {
dp[i] = values[i];
}
max_sum = max(max_sum, dp[i]);
}
return max_sum;
}
Best sum Any Tree Path โ
Oracle
๐1
๐๐ฆ ๐๐น๐ด๐ผ ๐ป ๐ ใ๐๐ผ๐บ๐ฝ๐ฒ๐๐ถ๐๐ถ๐๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ๐บ๐ถ๐ป๐ดใ
Photo
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> solve(vector<int>& nums) {
vector<vector<int>> ans;
int n = nums.size();
sort(nums.begin(), nums.end());
for (int i = 0; i < n - 2; ++i) {
if (i > 0 && nums[i] == nums[i - 1])
continue;
int left = i + 1, right = n - 1;
while (left < right) {
int sum = nums[i] + nums[left] + nums[right];
if (sum == 0) {
ans.push_back({nums[i], nums[left], nums[right]});
while (left < right && nums[left] == nums[left + 1]) ++left;
while (left < right && nums[right] == nums[right - 1]) --right;
++left;
--right;
} else if (sum < 0) {
++left;
} else {
--right;
}
}
}
return ans;
}
The Quest for Numerias Relics โ
SELECT
a.iban,
ROUND(SUM(CASE WHEN EXTRACT(QUARTER FROM d.dt) = 1 THEN d.amount ELSE 0 END), 2) AS q1,
ROUND(SUM(CASE WHEN EXTRACT(QUARTER FROM d.dt) = 2 THEN d.amount ELSE 0 END), 2) AS q2,
ROUND(SUM(CASE WHEN EXTRACT(QUARTER FROM d.dt) = 3 THEN d.amount ELSE 0 END), 2) AS q3,
ROUND(SUM(CASE WHEN EXTRACT(QUARTER FROM d.dt) = 4 THEN d.amount ELSE 0 END), 2) AS q4,
ROUND(SUM(d.amount), 2) AS year2023
FROM
accounts a
LEFT JOIN
declarations d ON a.id = d.account_id
WHERE
EXTRACT(YEAR FROM d.dt) = 2023
GROUP BY
a.iban
ORDER BY
a.iban ASC;
Tax Software
Meeshoโ
SELECT
c.email,
COUNT(s.url) AS total_active_sites
FROM
customers c
LEFT JOIN
sites s ON c.id = s.customer_id AND s.is_active = 1
GROUP BY
c.email
ORDER BY
c.email ASC;
Web hosting service
Meeshoโ
SELECT
u.email,
COUNT(t.id) AS total_transactions,
ROUND(SUM(t.amount), 2) AS total_amount
FROM
users u
LEFT JOIN
transactions t ON u.id = t.user_id
WHERE
YEAR(t.dt) = 2023
GROUP BY
u.email
ORDER BY
u.email ASC;
Payment System
Meeshoโ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
SDET Tech is hiring for SDE in Test
2022/2023 passouts
Apply Now :
https://forms.gle/2hZCAJHse7yJJ7YY9
2022/2023 passouts
Apply Now :
https://forms.gle/2hZCAJHse7yJJ7YY9
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
EYGDS is hiring for Junior Engineer
0 - 1 year experience
Skills : AWS / Azure , Linux , CI/CD
Send your resume : Shafwan.Saleem@gds.ey.com
0 - 1 year experience
Skills : AWS / Azure , Linux , CI/CD
Send your resume : Shafwan.Saleem@gds.ey.com