Adobe Interview Question for Developer Program Engineers


Country: India
Interview Type: In-Person




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

Working Code

#include<stdio.h>


int main()
{
char str[]="aaaaaaaaaaaaazzzzzzdcbbbaaa";
char arr[256];	//used for storing the indexes

int i;
	for(i=0;i<256;i++)
	arr[i]=-1;

int len=strlen(str);
char hash[len];

	for(i=0;i<len;i++)
		hash[i]=0;	


	for(i=0;i<len;i++)
		{
		  if(arr[str[i] ]==-1)
			 arr[str[i] ]=i;		//storing the first indexes
		}

	for(i=0;i<len;i++)
	hash[ arr[str[i] ] ]++;
		
	for(i=0;i<len;i++)
	if(hash[i]==1)
	{
		printf("%c",str[i]);
		break;
	}
	

	




return 0;
}

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

Idea is like this
I have stored the index of the first occurrence of every element in the string, in array arr.
Then while traversing the array i have incremented the count on that index in array hash
Then we can check the first element in hash whose count is 1,
and its index would be the index of the first non-repeating element in the string

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

Time - O(n)
Space - O(n)

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

what if str is "aabbccdd"?

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

Then there would be no output

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

@Luv It will not take care of the order in the string. For ex
"ccxbbba" it will give result as "a" bot should give x.We can easily implement this requirement in Java using LinkedHashMap.

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

#include <stdio.h>
#include <limits.h>
 
void find(char *s)
{
        int hash[256]={0},i,min=INT_MAX;
 
        for(i=0;s[i];i++)
                hash[s[i]]++;
 
        for(i=0;s[i];i++)
        {
                if(hash[s[i]]==1 && i<min)
                        min=i;
        }
        if(min!=INT_MAX)
        printf("First non-repeating character: %c",s[min]);
        else
                printf("No non-repeating character");
}
 
int main()
{
        char ch[10];
        fgets(ch,10,stdin);
 
        find(ch);
        return 0;
}

ideone.com/WuUQq

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

private static void FirstNonrepeatingCharacterinastring()
{
String inputstring = string.Empty;

Console.WriteLine("Enter the string : ");
inputstring = Console.ReadLine();

if (inputstring!=null)
{
char[] b = new char[inputstring.Length];
int[] hash = new int[256];

b = inputstring.ToCharArray();

for (int i = 0; i < inputstring.Length; i++)
hash[b[i]] = hash[b[i]] + 1;


for (int j = 0;j < inputstring.Length;j++)
{
if (hash[b[j]] == 1)
{
Console.WriteLine(b[j]);
break;
}
}
}

}

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

unsigned char arIndex[256]={0};
unsigned char buff[10] ={0};
strcpy( (char*)buff, "sbd3b2md");

unsigned int unLength = strlen((char*)buff);
unsigned int unCnt = 0;

while( unCnt < unLength )
{
arIndex[buff[unCnt]]++;
if ( arIndex[buff[unCnt]] > 1 )
{
cout << buff[unCnt];
break;
}
unCnt++;
}

- Virendra July 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

# include<stdio.h>
# include<conio.h>
# include<string.h>
# define max 256
int hasht[max];
main()
{
      int i,len;
      char str[max];
      printf("enter the string\n");
      gets(str);
      len=strlen(str);
      for(i=0;i<len;i++)
      {
           
            hasht[(str[i])%256]=hasht[(str[i]%256)]+1;                  
      }      
      for(i=0;i<len;i++)
      {
          
           if(hasht[str[i]%256]>1)
           {
                printf("leter that is rpeatd is :%c",str[i]);
                break;                
           }
      }
      
      getch();
}

- vinay sahu August 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Time complexity : O(n)
Soace Complexity: O(n)

char FirstNonReaptChar( char *s)
{
int even= 0,odd = 0, l = 0, r=sizeof(s)-1;
int Hash[sizeof(s)]= {0};
if( sizeof(s) % 2 == 0)
{
even = 1;
}
else
odd = 1;
while(l<sizeof(s) && r >=0)
{

if (even || odd)
{
if(l<r)
{
Hash[(int)s[l]]++;
Hash[(int)s[r]]++;
l++;
r--;
}
}

if(odd && l==r)
{
Hash[(int)s[l]]++;
l++;
}

if(r<l)
{
if (Hash[r] == 1)
{
return s[r];
}
else if (Hash[l] == 1)
{
return s[l];
}
else
return 0;

l++;
r--;
}
}
}

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

We can traverse the string character by character and keep adding characters in LinkedHashMap, with key=character and value=count of the character.
At end return 1st character from Linked HashMap whose count is 1.

- abhy July 17, 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