Hacker Rank Problems & Solutions
- Anand Nerurkar
- Jan 23
- 1 min read
Updated: Jan 27




chocofunction
==
static int chocofest(int n, int c, int m){
int choco=n/c;
int newchoco=0;
int wrap=choco;
while(wrap>=m){
newchoco=wrap/m;
choco=choco+newchoco;
wrap=(wrap mod c + newchoco
}
return choco;
}

scenario 1



find digits
==







static string catAndMouse(int x,int y, int z){
int cat1tomousedist=0;
int cat2tomousedist=0;
//x---cat1 y ---cat2 z---mouse
if(x<z){
cat1tomousedist=z-x;
}else{
cat1tomousedist=x-z;
}
if(y<z){
cat2tomousedist=z-y;
}else{
cat2tomousedist=y-z;
}
if(cat1tomousedist==cat2tomousedist){
return "mouse C";
}else if (cat1tomousedist<cat2tomousedist){
return "Cat A ";
}else{
return "Cat B";
}
}
}
Commenti