Professional Documents
Culture Documents
Assignment
Due Date: 11/11/2022
Name: Safa
Registration #: SP21-BSE-034
remain = n - maxi;
if (maxi >= remain) {
ans = remain;
}
else {
ans = n / 2;
}
cout << ans;
freq.clear();
return 0;
}
19.Rank the array according to rightmost set bit and least set bits
#include <bits/stdc++.h>
using namespace std;
class Pair {
public:
int index;
int rsb;
int setbit;
priority_queue<Pair> pq;
int setbit
= __builtin_popcount(ar[i]);
pq.push(Pair(i, k, setbit));
}
int rank = 1;
while (!pq.empty()) {
Pair p = pq.top();
pq.pop();
ar[p.index] = rank++;
}
}
int main()
{
int arr[] = { 1, 2, 3, 4, 5 };
rearrange(arr, N);
for (int i = 0; i < N; i++)
cout<<arr[i]<<" ";
return 0;
}
void gfg(vector<int>& v)
{
priority_queue<int> q;
for (auto x : v) {
q.push(x);
}
int cnt = 0;
while (q.size() >= 2) {
ele1--;
ele2--;
cnt += 2;
if (ele1) {
q.push(ele1);
}
if (ele2) {
q.push(ele2);
}
}
if (q.size() == 0)
cout << cnt << endl;
else
cout << -1;
}
int main()
{
vector<int> v = { 6, 3, 4 };
gfg(v);
}
vector<int> matchList;
priority_queue<int> pq;
matchList.push_back(top + 1);
matchList.push_back(cur + 1);
arr[top]--;
arr[cur]--;
if (arr[top] > 0)
pq.push(top);
if (arr[cur] > 0)
pq.push(cur);
}
int main()
{
int arr[] = { 5, 6, 7, 8 };
int n = sizeof(arr)/sizeof(arr[0]);
maxPairs(arr,n);
return 0;
}