Adobe Interview Question for Technical Support Engineers


Country: United States




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

Keep k variables. Each variable represents a factor. Each iteration, output the min variable then increment it by the respective factor. If a variable is equal to the currently output value, increment it (to avoid duplicates). When you've outputed n numbers, you are done.

O(kn) time, O(k) space

public static void printFactors(int[] values, int n) {

		int[] variables = new int[values.length];
		int output = 0;
		int i = 0;

		int toIncrement = 0;

		while (i < n) {

			toIncrement = 0;

			for (int j = 0; j < variables.length; j++) {

				if (variables[j] < variables[toIncrement]) {

					toIncrement = j;
				}
			}

			if (output < variables[toIncrement]) {
				
				output = variables[toIncrement];
				System.out.println(variables[toIncrement]);
				i++;		
			}

			variables[toIncrement] += values[toIncrement];
		}
	}

- SK July 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is ugly number problem. Please find the below code

void getNthUglyNo(unsigned n)
{
int ugly = new int[n];
int i2 = 0, i3 = 0, i4 = 0, i7=0;
int i;
int next_multiple_of_2 = 2;
int next_multiple_of_3 = 3;
int next_multiple_of_4 = 4;
int next_multiple_of_7 = 7;

int next_ugly_no = 1;
ugly[0] = 1;
for(i=1; i<n; i++)
{
next_ugly_no = Math.min(next_multiple_of_2, next_multiple_of_3, next_multiple_of_4,
next_multiple_of_7);
ugly[i] = next_ugly_no; 
if(next_ugly_no == next_multiple_of_2)
{
i2 = i2+1; 
next_multiple_of_2 = ugly[i2]*2;
}
if(next_ugly_no == next_multiple_of_3)
{
i3 = i3+1;
next_multiple_of_3 = ugly[i3]*3;
}
if(next_ugly_no == next_multiple_of_4)
{
I4 = i4+1;
next_multiple_of_4 = ugly[i4]*4;
}
if(next_ugly_no == next_multiple_of_7)
{
i7 = i7+1;
next_multiple_of_7 = ugly[i7]*7;
}

} /*End of for loop (i=1; i<n; i++) */
return next_ugly_no;
}

- ram.prasad.prabu July 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

35 is multiple of 7 and is not generated,reason is that we multiply given factors with generated numbers,and 5 is not generated so 35 is not generated,that why i am multiply numbers by i=1,2,3,4...... in my approach.
and for handle duplicates we can take an hash array.
My question is how to handle duplicates without extra space.

- rahulkumar5july July 07, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Just use a TreeSet to store the output numbers. If there is a duplicate, it will just dedupe since it's a set.

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

class pair{
	int key;
	int value;
	 pair(int key,int value){
		this.key=key;
		this.value=value;
	}
}

class pairComp implements Comparator<pair>{

	public int compare(pair o1, pair o2) {
		return o1.value-o2.value;
	}
	
}
public class NumberOfVariables {
	public static void main(String args[]){
		int[] k={2,3,4,7};
		int n=100;
		ArrayList<pair> al= new ArrayList<>();
		for(int i=0;i<k.length;i++){
			pair temp = new pair(k[i],k[i]);
			al.add(temp);
		}
		int[] ans=generate(al,n);
		System.out.println(Arrays.toString(ans));
	}

	private static int[] generate(ArrayList<pair> k, int n) {
		Collections.sort(k,new pairComp());
		for(int j=0;j<n;j++){
		}
		int[] ans=new int[n];
		int prev=-1;
		for(int i=0;i<n;i++){
			pair temp=k.get(0);
			if(prev!=temp.value)
				{
				ans[i]=temp.value;
				prev=ans[i];
				}
			else{
					i--;
				}
			temp.value+=temp.key;
			Collections.sort(k,new pairComp());
		}
		return ans;
	}

}

- abhishek4615 July 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

rahulkumar5july, Why did you get 10 in your output? 2, 3, 4, 6, 7, 8, 9 all make sense. But why 10?

- Anonymous July 08, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can anyone explain me how the number 10 came up from {2,3,4,7} ?

- Ishan July 08, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can anyone explain me how the number 10 came up from {2,3,4,7} ?

- Ishan July 08, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

because 10 is multiple of 2

- mmm September 11, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

10 is multiple of 2

- mmax September 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It is simple.
Just do the modulus for each number starting from 6 with the numbers in the set. If its 0 then, we can print that number else we check with other number in the given set.

As the set completes we move on to the next integer. It is same as the first solution, but with lesser complexity.

private static void giveTheFactors(int[] arr, int n) {
		// TODO Auto-generated method stub
		
			int numberToPrint_Not = 6;
		
			for(;numberToPrint_Not<=n;numberToPrint_Not++)
			{   	
				for(int i=0; i<arr.length;i++)
				{		
					if(numberToPrint_Not%arr[i] == 0)
						{
							System.out.println(numberToPrint_Not);
							break;
						}
				}
			}
	}}

- Anonymous January 21, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can make a sieve based approach to this problem. Take an array which will be used for marking the integers multiples and after that you can output all the integers that are marked in the array.

- ayushawasthi04 April 18, 2016 | 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