Research In Motion Interview Question
Software Engineer in TestsI remember in 'Programming Pearls' John Bentely told a story where he assigned the class to write a simple program and most students wrote in his opinion average code and he gave like C and 2 guys who worked in software industry wrote a 5 page code with all the software engineering principles and he gave those guys failing grade.
//Problem:
- Tarun Phaugat March 13, 2010//================
//I/P: CareerCup
//O/P: p_Cr__r_C
//Tasks:
//1. Reveres the string.
//2. Replace every vowel with space.
//Example:
//================
//I/P: CareerCup
//O/P: p_Cr__r_C
//ALGO:
//================
//1. reverse the string by using a temp and run till n/2
//check even or odd
// while swap check for all vowels.
//TEST CASES:
//================
//Functional tests:
//1. if all are vowels
//2. none is vowels
//3. all are spaces
//4. null string
//5. even odd string
//6. Limit Testing (BVA)
//7. integers in the string
//8. escape characters
//9. special characters
//N.Functional
//Performance:
//1. Send the same string and test for execution run time
//Memory
//2. keep on executing with same result and check for memory leaks
//stress
//4. run multiple calls of the same method
//security
//5. send string with escape characters and \0 , null string terminating sequence
//load:
//6. test with very long string
//localization\globalization
//7. test with mix if char and integers
//8. test with kanji[japenese] char
//9. test with unicode and ASCII and special char
//10. test with mix of unicode and japenese characters.
//TEST HARNESS:
//================
using System;
namespace problem
{
public class answer
{
static void Main()
{
string S = "CareerCup";
Console.WriteLine(replacereversestring(S));
System.Console.ReadLine();
}
//CODE:
//================
public static string replacereversestring(string s)
{
int strlen = s.Length;
char[] strarray = s.ToCharArray();
string Result = "";
if (strlen % 2 != 0)
{
int j = strlen-1;
for (int i = 0; j-i>=0; i++, j--)
{
if (strarray[i] == Convert.ToChar("a") || strarray[i] == Convert.ToChar("i") || strarray[i] == Convert.ToChar("o") || strarray[i] == Convert.ToChar("u") || strarray[i] == Convert.ToChar("e"))
{
strarray[i] = Convert.ToChar(" ");
}
if (strarray[j] == Convert.ToChar("a") || strarray[j] == Convert.ToChar("i") || strarray[j] == Convert.ToChar("o") || strarray[j] == Convert.ToChar("u") || strarray[i] == Convert.ToChar("e"))
{
strarray[j] = Convert.ToChar(" ");
}
answer.swap(i, j, strarray);
}
return Result = new string(strarray);
}
else
{
int j = strlen-1;
for (int i = 0; j - i >= 1; i++, j--)
{
if (strarray[i] == Convert.ToChar("a") || strarray[i] == Convert.ToChar("i") || strarray[i] == Convert.ToChar("o") || strarray[i] == Convert.ToChar("u") || strarray[i] == Convert.ToChar("e"))
{
strarray[i] = Convert.ToChar(" ");
}
if (strarray[j] == Convert.ToChar("a") || strarray[j] == Convert.ToChar("i") || strarray[j] == Convert.ToChar("o") || strarray[j] == Convert.ToChar("u") || strarray[i] == Convert.ToChar("e"))
{
strarray[j] = Convert.ToChar(" ");
}
answer.swap(i, j, strarray);
}
return Result = new string(strarray);
}
}
public static void swap(int i, int j, Char[] strarray)
{
char temp= strarray[i];
strarray[i]=strarray[j];
strarray[j]=temp;
}
}
}
//ORDER:
//================
//O(N)