Amazon Interview Question for Software Engineer / Developers






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

0. Keep boolean array for each character
1. Read string from left to right, Keep setting ith character value in boolean array
2. If you see a character whose bit is already set, return the character

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

Sort it and then scan it (compare arr[I]==arr[I+1])

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

This complexity > O(nlogn)
Possibly this is the least expected solution..

- AB July 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assuming a character set domain of 65535 characters, we can have a hashmap of size 65535.
Whenever we find a character not present in hashmap, we just insert it.
When we find a character present, we return with that character.

This is space intensive approach.

@Anonymous: Sorting a large string would be extremely cumbersome w.r.t time required.

- Akash July 19, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use namespace std;
class map {

private:
map<char,boolean> map;

public:
char processString(char * p){
int i=0;
while(i++ < strlenâ„—) {
if( map.find(p[i])==null){
map.add(p[i], true);
}
else {
return p [i];
}
}
int main() {
String readline;
cout<<"Enter the String"<<endl;
cin>>readline;
cout>>"First repeating charcter in the string">>processString(readline);
}
}

- rahul July 19, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

the same can also be done by storing the scanned characters of the String in a char array and using an efficient binary search to check the presence of a character in the array during the next insertion.

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

#include<iostream>

using namespace std;

void findFirstRepeatedChar(char m[], int length)
{
bool isExisted[256];
for(int i = 0; i < 256; i++)
isExisted[i] = false;

for(int i = 0; i < length; i++)
{

if(true == isExisted[m[i]])
{
cout<<m[i]<<endl;
return;
}
else
{
isExisted[m[i]] = true;
}
}
}
void main()
{
char a[] = "abcdefgbaew";
findFirstRepeatedChar(a, sizeof(a)/sizeof(char));
}

- mingzhou1987 July 19, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

u can add each char in a bst and if u find the repeating char u can simply print it.For inserting in bst it takes only Olog n)..

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

Create a boolean array, arr[26] and initialize it to 0
arr[0] corresponds to 'a'
arr[1] corresponds to 'b'
.
.
.
arr[25] corresponds to 'z'

Now suppose the string is "madame"
Scan the string, and for every character turn the boolean value in array to 1.
If there is a duplicate value, it would have already been encountered before for that index and the flag would already be 1, and hence the duplicate could be found.

for ex:
here
'm' => arr[ascii('m')- 65] = 1; // arr[12]=1
'a' => arr[ascii('a')- 65] = 1; // arr[0]= 1
'd' => arr[ascii('d')- 65] = 1; // arr[3] = 1
'a' => arr[ascii('a')- 65] is already 1, so this is the duplicate element.

Please let me know if there's something wrong with this approach.

- Anonymous August 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Create a boolean array, arr[26] and initialize it to 0
arr[0] corresponds to 'a'
arr[1] corresponds to 'b'
.
.
.
arr[25] corresponds to 'z'

Now suppose the string is "madame"
Scan the string, and for every character turn the boolean value in array to 1.
If there is a duplicate value, it would have already been encountered before for that index and the flag would already be 1, and hence the duplicate could be found.

for ex:
here
'm' => arr[ascii('m')- 65] = 1; // arr[12]=1
'a' => arr[ascii('a')- 65] = 1; // arr[0]= 1
'd' => arr[ascii('d')- 65] = 1; // arr[3] = 1
'a' => arr[ascii('a')- 65] is already 1, so this is the duplicate element.

Please let me know if there's something wrong with this approach

- ayanvit August 03, 2011 | 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