Adobe Interview Question for Developer Program Engineers


Country: India
Interview Type: In-Person




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

int isno(char c);
void main()
{
char s[]="gs1t43fd86gd2b3m0",t; ///suppose we got
int i=0,j=0,k;

while(i<strlen(s))
{
if(isno(s[i]))
i++;
else
{
t=s[j];
s[j]=s[i];
if(i>j+1)
{
k=i;
while(k>j)
{
s[k]=s[k-1];
k--;
}s[j+1]=t;
}else
s[i]=t;

i++;j++;
}
}


printf("%s",s);
}
int isno(char c)
{
return (c<='9'&&c>='0')?1:0;
}
int ischar(char c)
{
return ((c<='z'&&c>='a')||(c<='Z'&&c>='A'))?1:0;
}

- akiitbhu August 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

At max (3/2)n operations are performed.

It may stop while performing in-place operations, so for then the outer while (1) loop is there.
It will stop when the alphabets are placed completely. It means that all elements are in proper position!

void changeStringa1b2c3d4Toabcd1234(char str[], int size) {
  int mid = size>>1 ;
  int inext = mid - 1, restartIndex = 1;
  char ctemp = str[inext];
  while (1) {
    do {
      if ( ctemp >= 'a' && ctemp <= 'z' )
        inext = (ctemp - 'a') ;
      else inext = (ctemp-'1')+(size>>1) ;
      swap (&ctemp, &str[inext]);
    } while ( ctemp != str[inext] ) ;

    while ( (restartIndex < mid) && str[restartIndex] == ('a'+restartIndex) ) {
      restartIndex ++ ;
    }

    if ( restartIndex < mid ) {
      ctemp = str[restartIndex] ;
    } else break ;
  }
}

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

whether the string contains alternative alphabets and numerics or it can be at random.

- Siddharth Das July 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

2xn matrix written in row major fashion.
just transpose it

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

can you elaborate?

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

need a 2-d matrix for transposing,this has to be done inplace,,,correct me if m wrong

- min.bog9 July 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think we may use the ascii values of each charecter to sort the string

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

how??

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

main()
{
char a[10],a1[10],a2[10];
a="s1d3b2m0";
int j=0,k=0;
for(int i=0;i<strlen(a);i++)
{
if(a[i]>='a' && a[i]<='z')
{a1[j]=a[i];j++;}
else
{a2[k]=a[i];k++;}
strcpy(a,a1);
strcat(a,a2);
}
}

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

IN PLACE..??

- min.bog9 July 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

what are the assumptions on the string? are numbers and chars going to alternate all the time

- ssk1981 July 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 6 vote

Use the partition from quick sort.
Take two index. one at start and one at the end.

i=0, j=n;
while(i <j )
{
while(isAlpha(a[i++]);
while(isdigit(a[j--]);
swap(a[i], a[j]);
}

Handle Boundary Conditions and cross overs

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

It distorts the stability order. Cannot be used.

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

byte[] inputAscii = Encoding.ASCII.GetBytes("s1d3b2m0");
string output = string.Empty;
for (int i = 0; i < inputAscii.Length; i++)
{
if (inputAscii[i] >= 48 && inputAscii[i] <= 57)
{
output = output + (char)inputAscii[i];
}
else if (inputAscii[i] > 96 && inputAscii[i] < 123)
{
Console.Write((char)inputAscii[i]);
}
}
Console.WriteLine(output);

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

Extra variable can't be used!

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

private static void InplaceSort()
        {
                byte[] inputAscii = Encoding.ASCII.GetBytes("s1d3b2m0");
                string output = string.Empty;
                for (int i = 0; i < inputAscii.Length; i++)
                {
                    if (inputAscii[i] >= 48 && inputAscii[i] <= 57)
                    {
                        output = output + (char)inputAscii[i];
                    }
                    else if (inputAscii[i] > 96 && inputAscii[i] < 123)
                    {
                        Console.Write((char)inputAscii[i]);
                    }
                }
                Console.WriteLine(output);

}

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

good try!! but the final answer should be reflected in input variable(here: inputAscii which remain unaffected in your code)..

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

Counting sort?

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

Will require extra space..can use only one tmp variable right?

- Anonymos August 31, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String sort(String a) {
		
		char[] characters = a.toCharArray();
		int start = 0;
		
		for (int i = 0; i < characters.length; i++) {
			if(characters[i] >= 'a' && characters[i] <= 'z') {
				int k = i;
				while(k > start) {
					char temp = characters[k];
					characters[k] = characters[k - 1];
					characters[k - 1] = temp;
					
					k--;
				}

				start++;
			}
		}
		
		return new String(characters);
	}

- atul.bisaria July 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Step 1 : Count no.of Chars.
Step 2 : Start a pointer "i"from 0 and "j" from count+1.
Step 3: Increment i until you find a number or until count and j until you find a char or until end.
Step 4: Just swap the number and char and repeat step 3.

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

By your logic for the input string "s1d3b2m0" the output will be
"sbdm1230" and not "sdbm1320"
Am i correct?

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

char * GivenPatern( char *s)
{
int temp= 0, l=0;
{
while( l<n)
{

if(iSchar(a[l]) && isdigit(a[l+1]))
{
temp = l;
l++;
}
else if( (isdigit(a[l]) && isdigit(a[l+1])) || ((iSchar(a[l]) && iSchar(a[l+1])) )
{
l++;
}
else if(isdigit(a[l]) && iSchar(a[l+1]))
{
swap( a[l], a[l+1]);
l =temp;
l++;
}
if( m == sizeof(s)/2)
{
return s;
}
}
}

- Himanshu chauhan August 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Start from second element(since 1st is at its right place). note its index and character. place that character at right position(according to the final string) and hold the character and index replaced by it. Then place this character again at its proper position. There happens one situation that next index comes to the starting index. Since you have processed this index, you should set it to some unprocessed index. I set it to

strlen(str)/2 + 1

.
(It's my first post at the forum. Do comment if you like it :D)

#include<stdio.h>
#define swap(a, b) {(a)^=(b)^=(a)^=b;}
int main()
{
char str[50];
int n, next_index, lenby2;
char next_char;
sprintf(str, "a1a2b1b2");//abcdef123456
n = strlen(str);
lenby2 = n / 2;
printf("\ninput: %s", str);
for(next_index = 1, next_char = str[1]; n - 2; n--)
{
printf("\n %s %d %c", str, next_index, next_char);
if(next_char >= '0' && next_char <= '9')
{
 next_index = lenby2 + next_index / 2;
 swap(next_char, str[next_index])
}      
else
{
  next_index = next_index / 2;
  swap(next_char, str[next_index])
}
if(next_index == 1)
{
next_index = lenby2 + 1;   
next_char = str[next_index];          
}
}
printf("\noutput: %s", str);
getch();
return 0;
}

- Ankur September 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String args[]){

String s="s1d3b2m0";
//to "sdbm1320".

String result="";
String value="";
for(int i=0;i<s.length();i++){

if(s.charAt(i)>='0' && s.charAt(i)<='9' ){

result+=s.charAt(i);

}
else{

value+=s.charAt(i);
}

}

value+=result;
System.out.println(value);
}

- dadu February 15, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Use double pointers pointing to the first and the last element respectively.
The first pointer moves to right until it finds a number, while the right pointer moves to left until it finds a character.
swap the number and the character
iterate the two steps until the two pointers meet.

- AaronWang.ISO July 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

But it won't maintain the sequence of both the alphabets and numerics.

- Siddharth Das July 03, 2012 | Flag
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 votes

The question is to in place sort the string not output it online.

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

thats no prob....i think...
we can do this by using two index variables......
one pointing to the next element to scan & other point to next position to store that element...
if it is a char.... store it at the same instance........else if it is a number... store it in temp variable using temp=temp*10+element-'0'.
atlast instead of printing.... store it on array.

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

the temp variable is tricky. How about an array with millions of numbers and characters?

- AaronWang.ISO July 04, 2012 | Flag


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