IBM Oa Help | Oa Exam Helper
الذهاب إلى القناة على Telegram
We are here to clear All types of Exams Admin : @Codercpp001 (aka) KMK ✅ INTERVIEW HELP AVAILABLE 1-Coding Round 2-Aptitude and Reasoning Round 3-Communication round 4-Resume building 🎉Job updates will be posted here.
إظهار المزيد1 163
المشتركون
لا توجد بيانات24 ساعات
-47 أيام
+430 أيام
أرشيف المشاركات
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define ll long long
vector<vector<ll>> solve(ll n,ll k,vector<ll>&a,vector<ll>&b)
{
priority_queue<pair<double,pair<ll,ll>>> pq;
for(int i=0;i<n;i++)
{
double x=a[i];
double y=b[i];
double dis=sqrt(x+y);
pq.push({dis,{x,y}});
if(pq.size()>k) pq.pop();
}
vector<vector<ll>>ans;
while(!pq.empty())
{
ans.push_back({pq.top().second.first,pq.top().second.second});
pq.pop();
}
sort(begin(ans),end(ans));
return ans;
}
signed main()
{
ll n,k; cin>>n>>k;
vector<ll>a(n),b(n);
for(ll i=0;i<n;i++) cin>>a[i];
for(ll i=0;i<n;i++) cin>>b[i];
vector<vector<ll>>ans=solve(n,k,a,b);
for(auto it:ans) cout<<it[0]<<" "<<it[1]<<endl;
return 0;
}#include <iostream>
#include <vector>
using namespace std;
vector<bool> sieve(int max_val) {
vector<bool> is_prime(max_val + 1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i * i <= max_val; ++i) {
if (is_prime[i]) {
for (int j = i * i; j <= max_val; j += i) {
is_prime[j] = false;
}
}
}
return is_prime;
}
int main() {
int N;
cin >> N;
vector<int> A(N);
int max_val = 0;
for (int i = 0; i < N; ++i) {
cin >> A[i];
if (A[i] > max_val) {
max_val = A[i];
}
}
vector<bool> is_prime = sieve(max_val);
int prime_count = 0, composite_count = 0;
for (int i = 0; i < N; ++i) {
if (is_prime[A[i]]) {
prime_count++;
} else {
composite_count++;
}
}
int good_pairs = prime_count * composite_count;
cout << good_pairs << endl;
return 0;
}.
find good pairs in array
Infosys ✅
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
// your code goes here
int t;
cin>>t;
while(t--){
int a;
cin>>a;
int ans=INT_MAX;
vector<int>v(a);
unordered_map<int,int>mp;
for(int i=0;i<a;i++){
cin>>v[i];
mp[v[i]]++;
}
for(auto x:mp){
int r=a-x.second;
int l=x.first;
l*=r;
ans=min(ans,l);
}
ans=min(ans,a);
cout<<ans<<endl;
}
}
void dfs(int node, int parent, const vector>>& graph,
const vector& minActivity, vector& activity, vector& vulnerable) {
activity[node] = 0; // initial activity is 0
for (const auto& edge : graph[node]) {
int next_node = edge.first;
int weight = edge.second;
if (next_node != parent) {
dfs(next_node, node, graph, minActivity, activity, vulnerable);
activity[node] += activity[next_node] + weight;
}
}
if (activity[node] > minActivity[node]) {
vulnerable[node] = true;
}
}
int getMinServers(int server_nodes, int server_edges, const vector& server_from,
const vector& server_to, const vector& server_weight,
int minActivity_count, const vector& minActivity) {
vector>> graph(server_nodes + 1);
for (int i = 0; i < server_edges; ++i) {
graph[server_from[i]].emplace_back(server_to[i], server_weight[i]);
graph[server_to[i]].emplace_back(server_from[i], -server_weight[i]);
}
vector activity(server_nodes + 1, 0);
vector vulnerable(server_nodes + 1, false);
dfs(1, -1, graph, minActivity, activity, vulnerable);
int vulnerableCount = count(vulnerable.begin(), vulnerable.end(), true);
return vulnerableCount;
}
def Resource(A, B, C):
same_type_systems = (A // 3) + (B // 3) + (C // 3)
remaining_A = A % 3
remaining_B = B % 3
remaining_C = C % 3
different_type_systems = min(A, B, C)
remaining_A -= different_type_systems
remaining_B -= different_type_systems
remaining_C -= different_type_systems
remaining_A = max(0, remaining_A)
remaining_B = max(0, remaining_B)
remaining_C = max(0, remaining_C)
total_systems = same_type_systems + different_type_systems
leftover_resources = remaining_A + remaining_B + remaining_C
total_systems += leftover_resources // 3
return total_systems
Resource power ✅
