Amazon Interview Question for Quality Assurance Engineers


Team: QAE 1
Country: India
Interview Type: In-Person




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

Use a hash table.. loop through the char array and for each char insert the character as key and count as the value...

- Ajith February 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

map<char, int> countChar(char* str) {
    for(int i=0; str[i]; i++) {
        cnt[str[i]]++;
    } 
}

- !@$#@! February 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

map<char, int> countChar(char* str) {
map<char, int> map;
for(int i=0; str[i]; i++) {
cnt[str[i]]++;
}
}

- #$#@% February 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

THe easiest way is to use integer array with length 256 and update the value as we enounter each character.
int [] array = new int[256]
char charArray[] = str.toCharArray();
foreach(char c in charArray)
{
array[c]++;
}

- Ajith February 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is the classic solution from the times when a character was 8 bits. These days you should consider Unicode, too.

- Selmeczy, P├ęter February 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

For unicode array len would becm 2^16 since unicode char hv max len of 16 bits ....(hence it is good to check whether inp string is ascii or unicode)

- saurabh February 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

THe easiest way is to use integer array with length 256 and update the value as we enounter each character.
int [] array = new int[256]
char charArray[] = str.toCharArray();
foreach(char c in charArray)
{
array[c]++;
}

- Ajith February 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.amazon.techinterview;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

public class NoOfChars {
public static void main (String args[]){
Hashtable<Character, Integer> myHash = new Hashtable<Character, Integer>(26);
String myString = new String("gbvsyuxfasyusdfaxsasghdvsgcydegfrdywegvfwehyicv");
int length = myString.length();
for (int i=0; i<length; i++){
char ch = myString.charAt(i);
if (!myHash.containsKey(ch)){
myHash.put(ch,1);
}
else {
int presentCount = myHash.get(ch);
myHash.remove(ch);
myHash.put(ch, presentCount + 1);
}
}
Set<Entry<Character, Integer>> mySet = myHash.entrySet();
Iterator it = mySet.iterator();

while (it.hasNext()){
Map.Entry entry = (Map.Entry) it.next();
System.out.println(entry.getKey() + " : " + entry.getValue());
}
}
}

- Nilanjan Sil February 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int numberOfOccuranceOfPattern(char * str, char * pattern)
{
	int numOcc = 0;
	int i = 0;
	int j = 0;
	while(str[i] != '\0')
	{
		if(pattern[j] == str[i])
		{
			while(pattern[j] != '\0')
			{
				if(pattern[j] != str[i])
				{
					j = 0;
					break;
				}				

				j++;
				i++;

				if((pattern[j] == '\0') && ((str[i] == ' ') || (str[i] == '\0')))
				{
					numOcc++;
					j = 0;
				}
			}
		}
		else
		{
			i++;
		}
	}
	return numOcc;
}

- biswaranjan February 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;

public class B {
public static void main(String[] args) throws Exception{

Map<Character, Integer> map = new TreeMap<Character, Integer>();
String input = "Varun Saxena";

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

char in = input.charAt(i);
if(in == ' ' )continue;
if(map.get(in) != null){
int count = map.get(in);

map.put(in, ++count);

}else {
map.put(input.charAt(i), 1);
}
}

System.out.print(map);


}
}

- saxenavarun61 February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def charCount(s):
  m = {}
  for c in s:
    if c in m:
      m[c] += 1
    else: m[c] = 1
  for k in m.keys():
    print str(k)+":"+str(m[k])

- amshali February 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Hashtable;
public class CountCharOcurrence {
	public static void main(String[] args) {
		String word = "PROGRAM";
		char[] charArray = word.toCharArray();
		Hashtable<Character, Integer> hashtable = new Hashtable<Character, Integer>();
		for (char c : charArray) {
			System.out.println(c);
			if (hashtable.get(c) != null) {
				hashtable.put(c, hashtable.get(c) + 1);
			} else {
				hashtable.put(c, 1);
			}
		}
		System.out.println(hashtable.entrySet());
	}
}

This is my approach.

- sudhi.joshi April 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

please see my approach.

String name="rnagabandi";
HashMap<Character, Integer> hashMap = new HashMap<Character, Integer>();

int temp=0;
hashMap.put(name.charAt(0),1);

for (int i = 1; i < name.length(); i++) {

if(hashMap.get(name.charAt(i))!=null){
temp=hashMap.get(name.charAt(i));
hashMap.put(name.charAt(i),temp+1);
}else{
hashMap.put(name.charAt(i),1);
}

temp=0;
}

System.out.println(hashMap);

- raghu.nagabandi July 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

char string [] = "Test";
int Count = 1;
char Temp [] = string;
int i,j;


while ( temp[i] = '\0');
while(string[j] = '\0'){
if (temp[i] = string[j]){
count++;
}
j++;
}
cout<<temp[i]<<"occurance"<<count;
i++;
count = 1;
j = i;
}

- Mahes Karthic August 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String args[]){
String sat = "test";
sat =sat.toUpperCase();
int num = 0;

char[] sat1=sat.toCharArray();

for(int j=0;j<sat1.length;j++){
int count = 0;
for(int i=0;i<sat1.length;i++){
// System.out.print(sat1[i] + " ");

if(sat1[num]==sat1[i]){
count = count +1;

}

}


System.out.println(sat1[num] + " " + count);




num=num+1;
}


}

- sathishwaran January 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

# include <stdio.h>
# include <conio.h>

void main ()
{
int i,j,arr[256],size;
char *text;

printf("Enter the text : ");
scanf("%s",text);
i = 0;

for (i=0;i<255;i++)
{
arr[i]=0;

}
i=0;

while(text[i] != '\0')
{
	arr[(int)text[i]]++;
	i++;
}

for(i=0;i<255;i++)
{
 if( arr[i]>0)
 {
	printf("%c : %d\n",(char)i,arr[i]);
 }
}

printf("\n%s",text);


getch ();
clrscr();
}

- abhi.20dec September 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ruby Code

#finding number of occurance of the characters

data = String.new("good")
cnt = Array.new

l= data.length
for i in 0...l
  cnt[i]= data.count(data[i])  #counting characters
 end 
for k in 0...l
   puts  "Char #{data[k]} displayed  #{cnt[k]} times"
end

- Nitin Nazare November 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class CountCharOccurance
{

public static void main(String[] args)
{

String value = "Test@Tutor";

int[] count = new int[256];

value = value.toLowerCase();

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

count[(int)value.charAt(i)]++;
}

List<Character> printed = new ArrayList<Character>();

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

if (printed.contains(value.charAt(i)))
continue;

printed.add(value.charAt(i));

System.out.println("Occurrence of char [" + value.charAt(i) + "] - " + count[(int)value.charAt(i)]);
}
}

}

- Raghav July 29, 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