Codeforces|Leetcode|Codechef free solutions
Open in Telegram
Free codeforces, Codechef, Leetcode solutions are available 😍😍😍😍😍😍 Helped More than 200+ students to crack coding round in 2022 and helped placed them in Good companies. 🥳🥳🥳🤩🤩🤩 Dm @Cpsoln if you want help in coding round.
Show more4 317
Subscribers
No data24 hours
-137 days
-5230 days
Posts Archive
class Solution {
public:
const int MOD = 1e9 + 7;
int numberOfGoodSubarraySplits(vector& nums) {
int n = nums.size();
vector ones;
ones.reserve(n);
for (int i = 0; i < n; i++) {
if (nums[i] == 1) ones.push_back(i);
}
int m = ones.size();
if (m <= 1) return 1;
long long res = 1;
for (int i = 1; i < m; i++) {
res = res * (ones[i] - ones[i - 1]) % MOD;
}
return res;
}
};
class Solution {
public:
int makeTheIntegerZero(int num1, int num2) {
if (num1 < num2) {
return -1;
}
for (int steps = 0; steps <= 100; steps++) {
long long diff = num1 - static_cast(num2) * steps;
int bits = countBits(diff);
if (bits <= steps && steps <= diff) {
return steps;
}
}
return -1;
}
private:
int countBits(long long num) {
int count = 0;
while (num > 0) {
count += num & 1;
num >>= 1;
}
return count;
}
};
Anyone here attempting Google Girl Hackathon 2 from 9 am tommorow ?
Dm @Cpsoln to book your slot
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, e;
cin >> n >> e;
vector<vector<ll>> adj(n, vector<ll>(n, -1));
while (e-- > 0) {
ll u, v, t;
cin >> u >> v >> t;
adj[u - 1][v - 1] = t;
adj[v - 1][u - 1] = t;
}
string s(n, '0');
s[0] = '1';
queue<pair<string, ll>> Q;
ll t = 0;
bool ans = true;
while (ans && s[n - 1] != '1') {
ll now = 1000000001;
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
for (ll j = 0; j < n; j++) {
if (s[j] == '0' && adj[i][j] >= 1)
now = min(adj[i][j], now);
}
}
}
if (now == 1000000001)
ans = false;
else {
t += now;
Q.push({s, now});
string new_s = s;
for (ll i = 0; i < n; i++) {
if (s[i] == '1') {
for (int j = 0; j < n; j++) {
if (s[j] == '0') {
adj[i][j] -= now;
adj[j][i] -= now;
if (adj[i][j] == 0)
new_s[j] = '1';
}
}
}
}
s = new_s;
}
}
if (ans) {
cout << t << " " << Q.size() << endl;
while (!Q.empty()) {
cout << Q.front().first << " " << Q.front().second << "\n";
Q.pop();
}
} else {
cout << "inf";
}
return 0;
}
int n;
cin>>n;
vectorv(n);
vector>>pq(n+1);
for(int i=0;i>v[i];
v[i]--;
}
vectordp(n+1,0);
for(int i=0;i
https://www.codingninjas.com/studio/contests/scholarship-test-27th-to-28th-june-2023?utm_source=Growth-CS&utm_medium=RJ&utm_campaign=Cpsoln_Hardik_28June
Join the scholarship test of coding ninja and send ss at @Cpsolm
Then I will give c
For Cisco code-a-thon Slots available for 28th june
Dm @Cpsoln to book your slot otherwise no slots will be left.
CodeKaze Important Update ⚠️❗️
If you have given CodeKaze then register in this event to increase your chances of selection 👇
https://www.codingninjas.com/studio/contests/scholarship-test-27th-to-28th-june-2023?utm_source=Growth-CS&utm_medium=RJ&utm_campaign=Cpsoln_Hardik_28June
✅ Just click on Register for increasing chances of selection
