Infosys Interview Question for Developer Program Engineers


Country: India




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

I'm not sure about C but simply use a HashMap in Java.

- teli.vaibhav January 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Char[] Ch = {'A', 'B', 'A', 'C', 'B','A','C','A','A'};
int a=0,b=0,c=0;
for (int i = 0; i < Ch.Length; i++)
{
switch (Ch[i])
{
case 'A':
a++;
break;
case 'B':
b++;
break;
case 'C':
c++;
break;
}
}
Console.WriteLine("A={0}",a);
Console.WriteLine("B={0}", b);
Console.WriteLine("C={0}", c);
Console.ReadLine();

- Akshata January 20, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#include<stdio.h>
#include<conio.h>
int main()
{
static int i,a=0,b=0,c=0;
char A[]={'a','b','c','a','b','a','c'};
printf("%d\n",sizeof(A));

for(i=0;i<sizeof(A);i++)
{
if(A[i]=='a')
{
a++;
}
if(A[i]=='b')
b++;
if(A[i]=='c')
c++;
}
printf("a=%d b=%d c=%d",a,b,c);
getch();
return 0;
}

- kota pavan January 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

Java but it requires minor changes to adjust to C

public static void main(String[] args) {
	int[] count = new int[128];
	char[] input = { 'A', 'B', 'C', 'B', 'A', 'C', 'A', 'B', 'C', 'A', '#' };
	for (int i = 0; i < input.length; i++) {
	    count[input[i]]++;
	}
	for (int i = 0; i < count.length; i++) {
	    if (count[i] > 0) {
			System.out.println((char) (i) + " = " + count[i]);
	    }
	}
}

- thelineofcode January 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You are making the assumption that all characters belong to the english language.

- teli.vaibhav January 06, 2014 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 votes

Yes, that was my assumption. I updated my answer to handle or ASCII characters.

- thelineofcode January 06, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

There are 256 ASCII characters if you include the extended ones. :P But since this question was asked at Infosys I doubt if the interviewer thought so much.

- teli.vaibhav January 06, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Superb code.. thanks

- Anonymous January 10, 2014 | 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