Epic Systems Interview Question for Software Engineer / Developers






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

void stringReplace (char * in, char* out)
{
	int index=0;
	int i;

	//for first letter
	if ( 'A' == in[0] || 'a' == in[0])
	{
		if ( ' ' == in[1] )
			{out[index++] = 'O'; out[index++] = 'N';out[index++] = 'E';}

		else
		out[index++] =in[0];
	}else
		out[index++] =in[0];

	for (i=1; i< strlen(in)-1; i++ )
	{
		if ( 'a' == in[i] )
		{
			if ( (' ' == in[i+1] ) && (' ' == in[i-1] ) )
			{out[index++] = 'o'; out[index++] = 'n';out[index++] = 'e';}
			else out[index++] =in[i];
		}else if ( 'A' == in[i] )
		{
				if ( (' ' == in[i+1] ) && (' ' == in[i-1] ) )
				{out[index++] = 'O'; out[index++] = 'N';out[index++] = 'E';}
				else out[index++] =in[i];
		}else
			 out[index++] =in[i];

	}


	//for last letter
	if ( 'a' == in[strlen(in)-1] )
	{
		if ( ' ' == in[strlen(in)-2] )
			{out[index++] = 'O'; out[index++] = 'N';out[index++] = 'E';}

	}

	else if ( 'A' == in[strlen(in)-1] )
	{
		if ( ' ' == in[strlen(in)-2] )
			{out[index++] = 'o'; out[index++] = 'n';out[index++] = 'e';}

	}
	else
		out[index++] =in[strlen(in)-1];

	out[index] ='\0';
}

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

this doesnt work!! if i say "banana boy", it gives "bananone boy"

- Anonymous April 05, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

this code is good as Epic doesn't want you to use any inbuilt function or library.

- Anonymous April 08, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

is building a new string valid since we need to "replace"

- therethere October 13, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

import java.lang.*;
import java.util.*;

public class One
{

public static void getString (String s)
{
String output="";
StringTokenizer stk = new StringTokenizer(s);
String tok="";
while(stk.hasMoreElements())
{
tok = stk.nextToken();
if(tok.equals("A"))
{
tok = "ONE";
}
if(tok.equals("a"))
{
tok = "one";
}
output = output +" "+ tok;


}

System.out.println(output);

}


public static void main(String args[])
{
getString("A boy is playing in a garden");
}


}

- anonymous May 05, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String stringReplace(String str) 
{
    String regex = " ";
    String str1 = "a";
    String str2 = "A";
    StringBuilder builder = new StringBuilder();
    String[] parts = str.split(regex);
    for(int i=0; i<parts.size; i++)
    {
        if (parts[i].equals(str1))
            builder.add("one");
        else if (parts[i].equals(str2))
            builder.add("ONE");
        else 
            builder.add(parts[i]);
        if (i<parts.size-1)
            builder.add(" ");
    }
}

- Anonymous March 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

is this question asked during proctor test or during onsite test?

- gaandu babu March 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

onsite you poor idiot
they never ask such questions in the other case.

- gaandu baby August 19, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

why so serious?

- shithead October 05, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

i got this in the procter test !

- ~ December 14, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. size cannot be used for finding array size it should be "parts.length"
2. StringBuilder class has no add() method. Use append()
3. return statement missing. Before returing use toString() so that we can convert to String.
4. Also instead of hard coding space " " in line

if (i<parts.size-1)
            builder.add(" ");

use builder.append(regex);

Below is the complete code

public class HelloString{
	public static void main(String[] args){

		String t = stringReplace("A boy is playing in a garden");
		System.out.println(t);
	}
	
	static String stringReplace(String str) 
{
    String regex = " ";
    String str1 = "a";
    String str2 = "A";
    StringBuilder builder = new StringBuilder();
    String[] parts = str.split(regex);
    for(int i=0; i<parts.length; i++)
    {
        if (parts[i].equals(str1))
            builder.append("one");
        else if (parts[i].equals(str2))
            builder.append("ONE");
        else 
            builder.append(parts[i]);
        if (i<parts.length-1)
            builder.append(regex);
    }
   
    return builder.toString();
}
	
}

- Anonymous April 11, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Excellent, but it would be better if you use str.split(regex, -1) instead of str.split(regex), which will cut off the trailing blank space.

- Anonymous August 14, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can you use functions like split??
I think you cannot use built in functions.

- Anonymous April 13, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

split is to split the given string into words based on the regex(here it is space)..so in guess in the above logic we can use. The algo is

1. get the string
2. split the string into words based on regex(space here)
3. loop into the words and replace it based on the given criteria
4. return the modified string

- pondy April 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

When you can use regex y can't you guys just use the regex to replace the char??
Below is the VB.NEt code...
Imports System.Text.RegularExpressions

Module Replace

Sub main()
System.Console.Write("Please Enter the Sentance/ String to be replaced: ")
Dim Str As String = System.Console.ReadLine() '"A boy is playing in a garden"
Str = Regex.Replace(Str, "(( )+a( )+)|(^a( )+)|(( )+a$)", " one ")
Str = Regex.Replace(Str, "(( )+A( )+)|(^A( )+)|(( )+A$)", " ONE ")
System.Console.WriteLine(Str)
System.Console.Read()
End Sub
End Module

- Anonymous April 21, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

replace_A_and_a(char* mystring)
{
char* buff = mystring;

string replacedString;

char* token;
vector<string> vec;

token = strtok(buff, " ");
cout << token << endl;
vec.push_back(token);

while(token != NULL)
{
token = strtok(NULL, " ");
if(token)
{
cout << token << endl;
vec.push_back(token);
}
}

cout << vec.size() << endl;
for(int count = 0; count < vec.size(); ++count)
{
if(vec[count] == "A")
{
vec[count] = "ONE";
}
else if(vec[count] == "a")
{
vec[count] = "one";
}
replacedString += vec[count];
if(count < vec.size())
{
replacedString += " ";
}
}
cout << replacedString << endl;
}

- Nick May 11, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Nick
This is an excellent usage of strtok and vectors.

- Cookie May 15, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

class mainclass
{
public static void Main()
{
string str = "a boy in a garden a";
StringBuilder sb = new StringBuilder(str);
sb.Insert(0,' ');
sb.Insert(sb.Length," ");

sb.Replace(" a ", " one ");

Console.WriteLine(sb.ToString().Trim()+"test");

Console.ReadKey();






}

}

- Anonymous June 11, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

C# solution is

static string replaceStr(string _sent)
{
StringBuilder sb = new StringBuilder();
for(int i= 0; i < _sent.Length; i++)
{
if (_sent[i] == ('a'))
sb.Append("one");
else if (_sent[i] == ('A'))
sb.Append("ONE");
else sb.Append(_sent[i]);

}
return sb.ToString();
}


// you don't need to split on white space
// and string cannot compare anystring[i].equals(somestring)
// it should be string[i] == ('Character') because anystring[i] returns character

- Anonymous June 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class General {
static String replace = "A in the a fora testA";
public static void main(String[] args) {
replace= replace.replaceAll(" A ", " ONE ");
replace= replace.replaceAll("A ", "ONE ");
replace= replace.replaceAll(" A", " ONE");

replace= replace.replaceAll(" a ", " one ");
replace= replace.replaceAll("a ", "one ");
replace= replace.replaceAll(" a", " one");

System.out.println(replace);
}
}

- Anonymous July 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

it was never mentioned in the Qs to write huge chunk of shitty codes.
Be smart and use the following one-liner to do the job and try it out as well

ubuntu@ubuntu:~$ echo " A boy is playing in a garden"|sed 's/ a / one /' |sed 's/ A / ONE /'
 ONE boy is playing in one garden
ubuntu@ubuntu:~$

Thats it baby!

- googler August 19, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

your command can not handle the starting 'A', not to mention other special cases.

- Anonymous August 21, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

namespace stringbuilder
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();

Console.WriteLine("Enter string:");
string str = Console.ReadLine();




string newstr = p.ReplaceString(str);

Console.WriteLine(newstr);
Console.ReadLine();

}

public string ReplaceString(string str)
{
string sendstr = "";

string[] sendstr1 = splitstring(str);

//char[] newstr = str.ToCharArray();

for (int i = 0; i < sendstr1.Length; i++)
{
if (sendstr1[i].Equals("a"))
{
sendstr = sendstr + "one";
}
else if (sendstr1[i].Equals("A"))
{
sendstr = sendstr + "ONE";
}
else
{
sendstr = sendstr + sendstr1[i];
}

}



return sendstr;
}


public string[] splitstring(string str)
{
char[] charstr = str.ToCharArray();

int token = 0, initstring = 0; ;

for (int i = 0; i < charstr.Length; i++)
{

if (charstr[i] == ' ')
{
if(initstring>0)
{ token++; }
token++;
initstring = 0;
}
else if (i == charstr.Length - 1)
{
token++;
initstring++;
}
else
{
initstring++;
}
}


string[] strings = new string[token];

for (int i = 0; i < token; i++)
{
strings[i] = "";
}


int j = 0,chk = 0;

for (int i = 0; i < charstr.Length; i++)
{
if (charstr[i] == ' ')
{
j++;
strings[j] = strings[j] + charstr[i];
//if (chk > 0)
//{
// j++;
// chk = 0;
//}

}
else
{
if (i > 0)
{
if (charstr[i - 1] == ' ')
{
j++;
}
}
strings[j] = strings[j] + charstr[i];
}
}

return strings;
}
}
}

- ... August 21, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Very large and inefficient..not optimized

- TxAxl August 23, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Plz check if its correct:

while (str[i] != /n)
{
j=i;
k=0;

while (str[j] != "")
{
k++;
j++;
}

if (k==1)
{
if(str[i].equals('a'))

str[i].replace('a','one');

if(str[i].equals('A'))

str[i].replace('a','ONE');
}

i++;
}

- Priya October 03, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <string.h>

int main() {
char line[] = "A boy is playing in a garden";
const char* token = strtok(line," ");
do {
if ( !strcasecmp(token,"A") )
printf("one ");
else printf("%s ",token);
} while ((token=strtok(NULL," "))!=NULL);
printf("\b\n");

return 0;
}

- Srini October 21, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<string>
#include<sstream>
using namespace std;

int main()
{
string str = "A boy is playing in a garden";
string final = "";
string word;
stringstream stream(str);

while(getline(stream, word, ' '))
{
if(word == "A")
final = final + "ONE ";
else if(word == "a")
final = final + " one ";
else
final = final + " " + word + " ";
}
cout << final << endl;
return 0;
}

- codeit February 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

#include<iostream> at the beginning.

- codeit February 27, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

package EPIC;

import java.util.StringTokenizer;

public class ReplaceAaONEone {

	public static String getString(String s) {

		StringTokenizer ST = new StringTokenizer(s);
		String next = "";
		String output = "";
		while (ST.hasMoreElements()) {
			next = ST.nextToken();
			if (next.equals("A")) {
				output += "ONE ";
			} else if (next.equals("a")) {
				output += "one ";
			} else {
				output += next + " ";
			}
		}
		System.out.println(output);
		return output;
	}

	public static void main(String args[]) {
		getString("A boy is playing in a garden.");
	}
}

- albertchenyu March 05, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

public class charReplacement {

	public static void main(String[] args) {

		String str = "BanAna boy";
		StringBuilder newString = new StringBuilder();
		int i = 0;
		while(i < str.length()){
			if(str.charAt(i) != 'a' && str.charAt(i) != 'A'){
				newString.append(str.charAt(i));
				i++;
			}
			else{
				if(str.charAt(i+1) != ' '){
					newString.append(str.charAt(i));
					i = i+1;
				}
			else if(str.charAt(i) == 'a' && str.charAt(i+1)==' ' && str.charAt(i-1)==' ' ){
					newString.append("one ");
					i = i+2;
				}
				else if(str.charAt(i) == 'A'&& str.charAt(i+1)==' ' && str.charAt(i-1)==' '){
					newString.append("ONE ");
					i = i+2;
				}
				else{
					newString.append(str.charAt(i));
					i+=1;
				}
					
			}
		}
		System.out.println(newString.toString());

	}

}

- Tejaswi January 22, 2015 | 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