Adobe Interview Question


Country: India
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
2
of 2 vote

I think this may work

import java.io.*;

class Main
{
	public static void main(String ar[])
	{
		int n=43;
		double temp = 1;
		while( (temp%n) != 0)
		{
			temp = (temp*10) +1;
			System.out.println(temp);
		}
		System.out.println(temp);
	}

}

- vishal August 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

i thought something like that too... but it was also mentioned that. The range of output can be large that cant fit in integer or double. Sorry i forgot to mention that

- Joey August 10, 2013 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

This will work

int main(void)
{
     int arr[100000];
     for(int i=0;i<100000;i++)
     arr[i]=1;
     
     int i,n,num=0;
     cin>>n;
     
     for( i=0;i<1000000;i++)
     {
                num=(num*10+arr[i])%n;
                if(num==0)
                break;
     }
     
     for(;i>=0;i--)
     cout<<arr[i];
     getch();
     
}

- uN-kn0-wN August 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Great, but why not just make a count here with a while condition on num ==0(ofcourse initialize it with 1), rather than looping on a large number. That will save space i think. You don't need an array. You just need to output 1 as long as variable count. That will also take care of a long number possibility which can't fit in int, long ranges.

- Anonymous August 14, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Please comment on my solution, I think it works, Thanks!

int test1s(int n)
{
    int num1s = 0;
    while(n%10==1)
    {
        n = n/10;
        num1s++;
    }
if( n == 0 )
    return num1s;
else
    return 0;
}

string minmul3(int n)
{
string err = "err";
if (mod(n+10,10)!=3)
return err;

//we are solving the problem by iterative find the digit of b,which satisfies n*b=111....11.
//pre recomputed map[i] = s; st: mod(s*3+i,10) = 1;
int map[] = {7,0,3,6,9,2,5,8,1,4};

int res =0;
int count = 0;
while (test1s(res)==0)
{
	count++;
	int b = map[res%10];
	res = res/10 + b*n;
}
count = count + test1s(res);
string result;
result.resize(count+1);
memset(result.c_str(),'1',count);
result.c_str()[count+1] = 0;
return result;
}

- Tuotuo August 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
clrscr();
int a,i,b,count=1;
cout<<"Enter a";
cin>>a;
for(i=1;;i+=b)
{
count++;
b=pow(10,count);
if(a%10!=3)
{cout<<"\n wrong output";
getch();
return 0;
}
else
{
if(i%10==1)

{
if(i%a==0)
{
cout<<"\n Ans is "<<i<<" is divided by "<<a ;
getch();
return 0;
}
}
}
}
getch();
}

- Ankit August 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hi,
As per my understanding line if(i%10==1) will give if i has all 1's in it.but if you see
1111 (15) will not satisfy this condition.
Correct me if i am wrong.

- rachit singhal November 13, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I cant understand the question..could someone plz elaborate?

- Anonymous August 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include"stdio.h"
#define SIZE 100000

int modulo(int num[],int n)
{
int pre_ten=1;
int pre_mod=0;
int i=0,count=0;
while(i<SIZE)
{
count++; i++;
pre_mod=(pre_mod + pre_ten)%n ;
if(pre_mod==0) break ;
pre_ten=(pre_ten*10)%n ;
}
if(i==SIZE) return -1;
return count ;
}

// I assume that answer will come within 100000 digits

int main()
{
int num[SIZE] ;
int i;
for(i=0;i<SIZE;i++)
num[i]=1;
int n;
scanf("%d",&n);
int c=modulo(num,n) ;
printf("%d\n",c);
// c is total 1's in answer
// so we have answer string.
return 0;
}

- P.S. Patel August 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

start with no. of 1's as 0 in answer. Then dynamically increase no. of 1's in answer until we get the answer. We will get the ans when answer modulo n becomes zero. use this : (a+b)%n= (a%n + b%n)%n.
let at some time ans is 1111 (it mean we have 1111%n), then
11111%n= (10000 + 1111)%n = (10000%n + 1111%n)%n.
also 10000%n= (10*(1000%n))%n ( use of (a*b)%n= (a*(b%n))%n )

#include"stdio.h"
#define SIZE 100000

int modulo(int num[],int n)
{
	int pre_ten=1;
	int pre_mod=0;
	int i=0,count=0;
	while(i<SIZE)
	{
		count++; i++;
		pre_mod=(pre_mod + pre_ten)%n ;
		if(pre_mod==0) break ;
		pre_ten=(pre_ten*10)%n ;
	}
	if(i==SIZE) return -1;
	return count ;
}

// I assume that answer will come within 100000 digits

int main()
{
	int num[SIZE] ;
	int i;
	for(i=0;i<SIZE;i++)
	num[i]=1;
	int n;
	scanf("%d",&n);
	int c=modulo(num,n) ;
	printf("%d\n",c);
	// c is total 1's in answer
	// so we have answer string.
	return 0;
}

- P.S. Patel August 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

# In Python 
    n = int(sys.argv[1])  # get the integer 
    count = 1
    base = 1
    while base < n:
            base *= 10
            base +=1
            count += 1
    reminder  = base % n
    while reminder > 0:
            reminder *= 10
            reminder += 1
            reminder = reminder % n
            count+=1
    string = ''
    for i in range(0, count)
            string += '1'
    print string

- Esandman August 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

one point
You can get all 1's for n only if n = (2 pow k) -1. correct me if i am wrong.If it is true shouldn't we only try for ((2 pow k )-1)%a ==0.

- rachitrocks2k November 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void testFunction(int num) {
int count = 1, rm = 1;
while (rm > 0) {
rm = (rm * 10 + 1) % num;
count++;
}
while (count-- > 0)
System.out.print("1");
}

- santosh Dhakad May 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
using namespace std;
int main(){
cout<<"enter number";
unsigned int n;
cin>>n;
int n1=((1<<(n*2))-1);
printf("%x is divisible by %d",n1,n); //there is convert the n1 into binary
//the get the no. of 1's which is multile of n

return 0;
}

- shwetagupta.edu June 26, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More