Amazon Interview Question for Software Engineer / Developers






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

void printcount(int a[])
{
int i,b[256];
for(i=0;i<255;i++)
{
b[i]=0;
}
for(i=0;i<a.length;i++)
{
if(!b[a[i]])
{
b[a[i]]++;
}
else
{
printf("\n Element at index %d and its count is %d",a[i],b[a[i]]);
}
}
}

- TOPCODER March 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Java Solution:

public class StringManiputlation {

public static void main(String args[]) throws IOException{
Map<String,Integer> m = new HashMap<String,Integer>();
int length = args.length;
for (int i=0;i<length;i++)
{
Integer freq = m.get(args[i]);
m.put(args[i],(freq==null)?1:freq++);
}
System.out.println("Distinct characters"+ m.size());

}

- -A April 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry corrected version:


public class StringManiputlation {

public static void main(String args[]) throws IOException{
Map<String,Integer> m = new HashMap<String,Integer>();
int length = args.length;
for (int i=0;i<length;i++)
{
Integer freq = m.get(args[i]);
m.put(args[i],(freq==null)?1:freq+1);
}
Iterator<String> it = m.keySet().iterator();
while(it.hasNext())
{
String key = it.next();
System.out.println(key + m.get(key));
}

}

}

- -A April 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {
        map< char, int > charCount;
        string s( "amazon.com" );

        string::const_iterator end = s.end();
        string::const_iterator i = s.begin();

        for ( ; i != end; ++i )
                if ( ( *i >= 'a' && *i <= 'z' ) || ( *i >= 'A' && *i <= 'Z' ) )
                        ++charCount[ *i ];

        map< char, int >::const_iterator end1 = charCount.end();
        map< char, int >::const_iterator j = charCount.begin();

        for ( ; j != end1; ++j )
                cout << j->first << ", " << j->second << "\n";

        return 0;
}

- Si January 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can make use of the concept explained in geeksforgeeks.org/?p=16

- Gautham January 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If its only about alphabets then we can have a array of 26 integers and increment the count for the character each time a character occurs.
But i assume the question is not restricted to alphabets.
Then we have maintain a Dictionary and doubly linked list.(like any simple cache algo)

- Thiyanesh January 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can use a Hashtable with the alphabetsa as key and the objects intially to 0.
Now for every alphabet we see increment the count in the hash table and finally we end up having the counts...

public class count {

public static void main(String args[])
{
String str="amazon.com";
char[] ele=str.toCharArray();
Hashtable<Character, Integer> elements=new Hashtable<Character, Integer>();

for(int i=0;i<ele.length;i++)
elements.put(ele[i], 0);

for(int i=0;i<ele.length;i++)
{
elements.put(ele[i], (elements.get(ele[i])+1));

}

for(int i=0;i<ele.length;i++)
System.out.println(ele[i]+"count"+elements.get(ele[i]));

}

}

- Anonymus February 17, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i guess its optimal to use a technique which can give us a solution in O(n) complexity. i think thts the sole purpose of the interviewer to test your skills and see if you can do it in O(n) complexity.

- techie February 26, 2010 | 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