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
Amazon ml summer school 2-3 slots available
Dm @Cpsoln
class Solution {
private static final int MOD = 1_000_000_007;
private static final int MAX_INVERSIONS = 400;
public int numberOfPermutations(int n, int[][] requirements) {
Map reqMap = new HashMap<>();
for (int[] req : requirements) {
reqMap.put(req[0] + 1, req[1]);
}
long[][] permCounts = new long[n + 1][MAX_INVERSIONS + 1];
permCounts[0][0] = 1;
for (int length = 1; length <= n; length++) {
for (int inv = 0; inv <= MAX_INVERSIONS; inv++) {
for (int newPos = 0; newPos < length; newPos++) {
int prevInv = inv - newPos;
if (prevInv >= 0) {
permCounts[length][inv] = (permCounts[length][inv] + permCounts[length - 1][prevInv]) % MOD;
}
}
}
if (reqMap.containsKey(length)) {
int targetInv = reqMap.get(length);
for (int inv = 0; inv <= MAX_INVERSIONS; inv++) {
if (inv != targetInv) {
permCounts[length][inv] = 0;
}
}
}
}
long result = 0;
for (long count : permCounts[n]) {
result = (result + count) % MOD;
}
return (int) result;
}
}
class Solution {
public int minOperations(int[] nums) {
int n = nums.length;
int operations = 0;
boolean flip = false;
for (int i = 0; i < n; i++) {
int actualValue = nums[i] ^ (flip ? 1 : 0);
if (actualValue == 0) {
operations++;
flip = !flip;
}
}
return operations;
}
}
After 4940+ subscribers will upload C
React krdo guys attendance lagao😁
class Solution {
public int minOperations(int[] nums) {
int n = nums.length;
int operations = 0;
for (int i = 0; i <= n - 3; i++) {
if (nums[i] == 0) {
nums[i] = 1 - nums[i];
nums[i + 1] = 1 - nums[i + 1];
nums[i + 2] = 1 - nums[i + 2];
operations++;
}
}
for (int i = n - 3; i < n; i++) {
if (nums[i] == 0) {
return -1;
}
}
return operations;
}
}
class Solution {
public int minimumOperations(int[] nums) {
int operations = 0;
for (int num : nums) {
int remainder = num % 3;
if (remainder == 1 || remainder == 2) {
operations += 1; by 3
}
}
return operations;
}
}
