Interview Question for Developer Program Engineers


Country: Ukraine
Interview Type: Written Test




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

/* This solution is definitely not optimal. */
static void printNumbersWithoutRepeatingDigits(int start, int end){
		
	String strInt;
	List<String> arrlist = new ArrayList<String>();
		
	while(start <= end){
		
		strInt = String.valueOf(start);
			
		if(doesNotContainRepeatingDigits(strInt))
			arrlist.add(strInt);
			
		start++;
	}
		
	for(int i = 0; i < arrlist.size(); i++){

		System.out.print(arrlist.get(i));
	
		if((i+1) < arrlist.size())
			System.out.print(", ");
	}
}

static boolean doesNotContainRepeatingDigits(String s){
	int firstOccurrence, secondOccurrence;
	
	for(int i = 0; i < 10; i++){
			
		firstOccurrence = s.indexOf((char)(i+48));
		secondOccurrence = s.indexOf((char)(i+48), firstOccurrence+1);
			
		if(secondOccurrence != -1)
			return false;
	}
	
	return true;
}

- Jackmerius Tacktheritrix October 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

duplicate

question?id=5982716570894336

- siva October 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What if possible range is from 0 to 987654321 it makes this problem more complex

- glebstepanov1992 October 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It is easy if you follow my post in the given link, but it involves number to string conversion.

For the case you mentioned, frame a string like below and call it as pattern

"111111111 222222222 333333333 444444444 555555555 666666666 777777777 888888888 99999999"

if single digit number
	digits are not repeated
else
	if pattern.contains(num.toString())
		digits are repeated
	else
		digits are not repeated

test case:

11
22
33
111
222
333
1111
2222
3333
.
.
.
.
888888888 < 987654321 which is the biggest number with repeated digits

all these numbers when converted to string is a sub string in the pattern :-)

- siva October 03, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

What is the complexity of your solution?

- glebstepanov1992 October 03, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

time complexity is O(n * m) where 'n' ranges from 0 to 987654321 and 'm' ranges from 0 to 9 (number of digits) considering Contains and ToString operation for every 'n'
space complexity is O(1) as the size of the pattern string is constant

correct me if I'm wrong.

- siva October 04, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

* 'm' ranges from 1 to 9

- siva October 04, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think it's to much for this task, maybe there is any better solution

- gstepanov@griddynamics.com October 04, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

void rem_dup(int min, int max)
{
int i,val,dig;
int Isloop ,num[10] = {0};
for(i = min; i <= max; i++)
{
val = i;
Isloop = 0;
memset(num, 0, sizeof(num));
while(val != 0)
{
dig = val % 10;
val = val / 10;
num[dig]++;
if(num[dig] > 1)
{
Isloop = 1;
break;
}
}
if(!Isloop)
printf("%d\t", i);
}

}

- Sakthivel Sethu ,Software Engineer ,Bangalore October 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

start = 98
end = 103
results = []

for n in range(start + 1, end):
    t = list(str(n))

    if len(t) == len(set(t)):
        results.append(n)

print 'Results:', results

Results: [102]

- apero December 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

for(int num=98;num<=104;num++)

{
int n = num;
List<Integer>list=new ArrayList<Integer>();
int rev=0,rmd;
while(n > 0)
{
rmd = n % 10;
list.add(rmd);
rev = rev * 10 + rmd;
n = n / 10;
}
int count=0;
for(int j=0;j<list.size();j++)
{

for(int k=j+1;k<list.size();k++)
{
if(list.get(j)==list.get(k))
{
count++;
break;
}

}

}

if(count==0)
System.out.println(num);
}
}

- Gopal July 09, 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