Adobe Interview Question
SDE-3sCountry: United States
private static int countRep(int[] numbers, int toCheck) {
int count = 0;
for (int element : numbers) {
if (element < 9) {
if (element == toCheck) {
count++;
}
} else {
int rem = 0;
int org = element;
while (org > 0) {
rem = org % 10;
if (rem == toCheck) {
count++;
}
org /= 10;
}
}
}
return count;
}
int repeatedDigitCount(int num,int k){
- Anonymous January 15, 2017int i,count = 0;
for(i=0;i<=num;i++){
if(i==0 && k==0)
{
count++;
continue;
}
if(i==1 && k==1)
{
count++;
continue;
}
int val = i;
while(val>1){
if(val%10 == k){
count++;
}
val = val/10;
if(val==k && val!=0){
count++;
}
}
}
return count;
}