private static int minOperationsToReduceToOne(int n) { int operations = 0; // Counter to store the number of operations // Iterate until n becomes 1 while (n > 1) { boolean divided = false; // Flag to check if we were able to divide // Full for loop to find the largest divisor from n-1 to 2 for (int x = n - 1; x > 1; x--) { if (n % x == 0) { // If n is divisible by x n = n / x; // Divide n by x operations++; // Increment the operations count divided = true; // Set the flag to true break; // Exit the loop after the division } } // If no division happened, we subtract 1 from n if (!divided) { n -= 1; // Subtract 1 from n operations++; // Increment the operations count } } return operations; // Return the total number of operations } }
{ int x = 57; int count = 0; int n = 0; for (int i = x - 1; i > 2; i--) { if (x % i == 0) { n = x / i; count++; break; }else{ while(!(x%2==0)){ x = x -1; count++; } } } while (n != 1 && n != 0) { n = n - 1; count++; } System.out.print(count); } is this correct?
Thank you bro
This video may help coming capgemini exam
Nice
thank you so much
private static int minOperationsToReduceToOne(int n) {
int operations = 0; // Counter to store the number of operations
// Iterate until n becomes 1
while (n > 1) {
boolean divided = false; // Flag to check if we were able to divide
// Full for loop to find the largest divisor from n-1 to 2
for (int x = n - 1; x > 1; x--) {
if (n % x == 0) { // If n is divisible by x
n = n / x; // Divide n by x
operations++; // Increment the operations count
divided = true; // Set the flag to true
break; // Exit the loop after the division
}
}
// If no division happened, we subtract 1 from n
if (!divided) {
n -= 1; // Subtract 1 from n
operations++; // Increment the operations count
}
}
return operations; // Return the total number of operations
}
}
How many coding questions and how much time?
Can I code in javascript in coding round? or in Python?
Hey my coding round is in this month can I use the python language for solving DSA questions
No. Only C,C++, java
How was your coding test ? How many test cases where there ?
mast h bhai
Which batches question ❓
{
int x = 57;
int count = 0;
int n = 0;
for (int i = x - 1; i > 2; i--) {
if (x % i == 0) {
n = x / i;
count++;
break;
}else{
while(!(x%2==0)){
x = x -1;
count++;
}
}
}
while (n != 1 && n != 0) {
n = n - 1;
count++;
}
System.out.print(count);
}
is this correct?