Adobe Interview Question for Software Engineer / Developers


Country: India
Interview Type: Written Test




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

Understandable version of code.

#include<stdio.h>
#include<stdlib.h>

void  print_multiple_of_all_ones(int num)
{
    int count=1,rem=1;

    while(rem)
    {
        rem = ( rem*10 + 1 ) % num;
        count++;
    }

    while(count--)
        printf("1");

    printf("\n");
}

int main()
{
    int num;
    scanf("%d",&num);
    print_multiple_of_all_ones(num);
    return 0;
}

- rakesh June 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

can we also find the multiplier to the given number in the same algorithm ?

- jaks June 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@jaks Yes, just edit the main loop a little:

int q = 0;
printf("Quotient = ");
while(rem)
{
    q = ( rem*10 + 1 ) / num;
    printf("%d", q);
    rem = ( rem*10 + 1 ) % num;
    count++;
}
printf(" Number = ");

- bazinga September 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

What about controlling integer overflow? we should use an array of this type where inside the structure we only use an integer.

typedef struct smallInt {
  int num:4 ;
}smallInt;

- Psycho September 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 5 vote

#include<stdio.h>
#include<conio.h>
void main()
{ clrscr();
int n, num=1, r, x=1;
scanf("%d",&n);
while(x)
{ r=num%n;
if(r==0)
x=0;
else
{
num=r*10 +1;
}
printf("1");
}
getch();
}

- shagun June 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

At some point the value of r will be overflowed, which is clearly mentioned in question. E.g. after 11111 (limit of int is 32,767).

- mads June 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@mads overflow condition is for 11111..... not for 'n',,, i hv used n as the input value and and num & r as jus a temporary variable...111...are displayed by using printf

- shagun June 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@shagun:u using value of mod r=num%n to calculate the next num i thnk num will never be grter than 11...how it will work den

- shivi116 June 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@shagun: apologize for pointing wrong variable. I was talking about num. num will grow like 1...11...111...1111 but after 11111 num will be overflowed.

- Anonymous June 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Anonymous: i thnk num will never exceed 11.....

- shivi116 June 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

num will never exceed 91 since remainder will b 9 at max so 9*10+1....max 91...dis way no prob of overflow watever b the value of n(bt value of the number input shud b in d range of integer)

- shagun June 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

good solution

- Anonymous June 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@shagun: i didn't get how the remainder will never exceeds 9

take example of n = 13
in first iteration: r = 1 and num = 11
in next iteration: r = 11

- Coder July 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think what shagun is trying to tell is that r will never exceed (n-1)*10+1
Now , as long as n <= 3276..i don't think there should be a overflow issue because of r.
Correct me if i am wrong

- Mukund November 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

sorry i forgot to check for unit digit '3'.. bt d logic is clear from d code..

- shagun June 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

answer in Java:

public static  void printAllOnes(int n)
	{
		System.out.println("Input: "+n);
		if(n%10!=3) {
			System.out.println("Output: Error !");
			return;
			}
		else {
			boolean cont = true;
			int num = 0;
			int length = 0;
			// get integer consisting only 1's
			while(cont){
				if(num>0 && num%n==0) 
				{
					cont = false;
					System.out.println("Output:"+num);
				}
				else{
					num = (int) (num + Math.pow(10, length));
					length ++;
					}
			}
		}
	}

- Anonymous June 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<conio.h>
#include "stdlib.h"




void main()
{
int n, num=1, r, x=1;
scanf("%d",&n);
while(x)
{ r=num%n;
if(r==0)
x=0;
else
{
num=num*10 +1;
}
if(num>65535)
{
printf("integer overflow");
return;
}
}
printf("\t %d",num);
}

- Anonymous June 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>

int main(){
int count=0;
int number,k;
scanf("%d",&number);
int temp = number;
printf("number = %d \n",number);
while(temp != 0){
temp = temp/10;
count++;
}

int start = 0;
for(k=0;k<count;k++){
start = start*10+1;
}
start = start*10+1;
printf("the start value is %d \n",start);
while(start != 0){
start = start*10+1;
count++;
start = start%number;

}
for(k=0;k<=count;k++){
printf("1");
}
printf("\n");
return 0;
}

- Anonymous June 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Hi,

As per my understanding of the problem we need to print multiples of the number ending in 3 which consists of all 1's.But how is 111(7) a multiple of 3 and 111111(63) a multiple of 13.Can somebody elaborate the question please.
Thanks in advance.

- vikas June 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@vikas2005v. buddy 111 is base 10 representation nd not base 2

- bashrc June 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void test() {
System.out.println(bar(3));
System.out.println(bar(13));
System.out.println(bar(23));
}

private String bar(int x){
int i = 0;
int rem = 0;
StringBuilder sb = new StringBuilder();
do{
rem += foo(i, x);
i++;
sb.append("1");
} while (rem % x !=0);
return sb.toString();
}

private int foo(int power, int mod){
int retVal = 1;
for(int i =0; i<power; i++){
retVal = (retVal*10) % mod;
}
return retVal;
}

- Anonymous July 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

change method bar:

private String bar(int x){
int i = 0;
int rem = 0;
StringBuilder sb = new StringBuilder();
do{
rem = (rem+foo(i, x))%x;
i++;
sb.append("1");
} while (rem !=0);
return sb.toString();
}

- Anonymous July 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*This code properly maintains overflow by returning the number of 1's in the answer */
int f(int num)
{
    int a = 111;
    int length=3;
    
    while(1)
    {
        if(a%num == 0 ) return length;
        a = a*10 + 1;
        if(a>=num) a%=num;
        length++;
        
    }
}

int main()
{
    int length = f(23);
    int i;
    for(i=1; i<=length; i++)
    printf("1");
    printf("\n");
    return 0;
}

- rajdeepgupta20 July 21, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
		long long n;
		cin>>n;
		long long cur = 1;
		while(cur%n!=0){
			cur = cur*10+1;
		}
		cout<<cur<<endl;
	}
	return 0;
}

- asen October 12, 2015 | 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