Interview Question

Software Development Engineer In Test (SDET) Interview

-Bangalore

Microsoft

In a sequence of alphabets (like aaabbddaabbcc) write a program to find the number of the consecutive alphabets in and print the alphabet and number. example :if input is aaabbddaabbcc then output should be 3a, 2b, 2d, 2a, 2b, 2c

Answer

Interview Answers

4 Answers

2

#Iinclude #include main() { char str[ ]; printf("Enter the input\n"); scanf("%c",&str); printf("input:%c",str); int len= strlen(str); int alp[26]; if(str!='NULL' && len!=0) { for(int i=0;i

MD UBEAD BASHA on

0

I misunderstood the question, and wrote the program for printing number of a's or b's etc., present in the sequence when I showed him he asked me to code according to his requirement, the program should produce output without any errors,during this time he was writing something in the laptop. I wrote program correctly. He said ok.

Anonymous on

0

void PrintAlphaNum( string str ) { if ( (str == null) || str.Length == 0 ) { return; } char lastChar = str[0]; int count = 0; foreach( char ch in str ) { if ( ch == lastChar ) { count++; } else { Console.Write("{0}{1}, ", count, lastChar ); count = 1; lastChar = ch; } } if ( count > 0 ) { Console.WriteLine("{0}{1}", count, lastChar ); } }

MessyHack on

1

Simple Java Code: String str = "aaabbddaabbcc"; for(int i = 0; i < str.length()-1; i++) { int count = 0; for(int j = i; j < str.length(); j++) { if(str.charAt(i) == str.charAt(j)) count++; else { i += count - 1; break; } } System.out.print(Integer.toString(count) + Character.toString(str.charAt(i)) + ", "); }

Namrata on

Add Answers or Comments

To comment on this, Sign In or Sign Up.