Adobe Interview Question for Member Technical Staffs


Country: India
Interview Type: In-Person




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

Take the sum and check for divisiblity by 3.

So maintain running sum (mod 3, to cater to overflows) and check if sum is 0 when stream ends.

It does not matter whether you get the most significant digit first.

This assumes base 10.

- Anonymous June 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

yes you are right. digits sum of a number divisible by 3 is always divisible by 3.
Good to know. Thanks.

- AlgoAlgae June 27, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Added in which direction? in front or back?

1 <- 2 <- 3 = 123?

or

3 -> 2 -> 1 = 321?

- AlgoAlgae June 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Does not matter. See other answer.

- Anonymous June 27, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

void multiple0f3()
{
	int previousmod=0;
	int curmod=0;
	char ch;
	bool test[100]; //Assuming max of 100 digits
	int k=0;
	cin>>ch;
	while(ch!='e')
	{
		int d=ch-'0';
		curmod=d%3;
		previousmod=(curmod+previousmod)%3;
		if(previousmod==0)
			test[k++]=true;
		else
			test[k++]=false;
		cin>>ch;
	}
	cout<<endl;
	for(int i=0;i<k;i++)
		cout<<test[i]<<endl;
}

- Shankar Lal Agarwal June 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

(digit1+digit2+digit3)%3 should be equal to zero.

- Mohit Mehta July 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Umm.... 4231.

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

as the numbers are coming in, we can keep doing processing on these numbers by adding as the number comes and % the sum with 3, so the resultant output will be 0,1,2 we add this output with the next number coming in the stream and again % the sum by 3.

But this has the disadvantage of operating all the times even when not asked/required.

- tomarasha July 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Scanner;


public class divby3 {
public static void main (String args[])
{
int sum=0;
int i = 1;
while (i==1)
{
Scanner in =new Scanner(System.in);
String digit=in.next();
int number=Integer.parseInt(digit);
sum=sum+number;
System.out.println(sum);
if (sum%3==0)
{
System.out.println("Divisible by 3");
}
else
{
System.out.println("Not divisibe by 3");
}
System.out.print("You want to continue?");
String response=in.next();
i=Integer.parseInt(response);
}
}
}

- Ujjawal Sharma July 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mod3
{
class Program
{
static void Main(string[] args)
{
int[] arr=new int[10];
int i,sum=0;
char ch='y';

for(i=0;i<10;i++)
{
Console.WriteLine("Enter the digit");
arr[i] = Convert.ToInt32(Console.ReadLine());
sum = sum + arr[i];
Console.WriteLine(sum);
Console.WriteLine("Do you want to continue (Y/N) :");
ch = Convert.ToChar(Console.ReadLine());
switch (ch)
{
case 'y':
case 'Y':
continue;
case 'n':
case 'N':

if (sum % 3 == 0)
{
Console.WriteLine("Divisble by 3");
break;
}
else
{
Console.WriteLine("Not divisible by 3");
break;
}

default:
Console.WriteLine("Enter the correct value");
break;
}



}



}
}
}

- itshemant09 August 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package test;
import java.io.DataInputStream;
import java.io.IOException;
public class MultipleOf3 {
	public static void main(String [] args)
	{
		int in;
		DataInputStream br=new DataInputStream(System.in);
		try {
			int sum=0;
			while((in=br.read())!='a')
			{
				Character c=(char)in;
				int i = 0;		
				if(c<='9'&&c>='0')
				{
					i=Integer.parseInt(c.toString());
					sum+=i;
					System.out.print(i);
					if(sum%3==0)
					{
						break;
					}
				}	
			}
			System.out.println();
			System.out.println("div by 3!!!");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

- sudeep91soni January 13, 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