Epic Systems Interview Question for Software Engineer / Developers






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

String input = "This is a sentence in English";
String[] inputSplit = input.split("a");
input = inputSplit[0];
for(int i=1; i<inputSplit.length-1; i++) {
   input += "the"+inputSplit[i];
}

OR

String input = "This is a sentence in English Language";
input.replaceAll("a","the");

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

dude, wht about double occurence of a or when it occur more than 1

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

simple soln for that... add spaces on either side

input.replaceAll(" a "," the ");

- Rishi October 24, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Oh, I thought, It was asked to replace occurance of "a" with "the". But, the logic seems correct!

- logNguy December 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Class Prob
{
String Actual="A man walks in with the Bat";
String converted="";
StringTokenizer st= new StringTokenizer(Actual);


if(st.hasMoreTokens())
{
if(st.nextToken.equals("a")
	Converted= Converted + "the";
else
	Converted= Converted + st.nextToken;
}
System.out.Println(Converted);

}

- Anonymous December 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 votes

This does NOT work! bad logic!!

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

Am a fresher.. Do correct me if I am wrong


char str= "this is a test string";
for(i=0;i<strlen(str);i++)
{
if(str[i]=='a' && str[i+1]==' ' && str[i-1]==' ')
{
replace(str, 'a', "the");
}
printf("%c", str);

- Shyam February 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

come on, you forgot this
if(str[i]=='a' && i>1 && i<str.length()-1 && str[i+1]==' ' && str[i-1]==' ')

- chenyang.feng.cn April 07, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

int main()
{
int i,k;
char buf1[100];
char buf2[]="aaaaaaaaa";
int j=strlen(buf2);
printf("The length of the string is %d\n",j);
k=0;
for(i=0;i<j;i++)
{

if(buf2[i]=='a')
{
buf1[k++]='t';
buf1[k++]='h';
buf1[k++]='e';
}
else
buf1[k++]=buf2[i];

}

k=0;
while(buf1[k]!='\0')
{
printf("%c",buf1[k]);
k++;
}

}


I am a Finance major and was called for S/W dev.becoz I have an undergrad in CS. I am sure I cannot write code like you guys but I am just sharing my code too

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

Here is the same man again... Reliability 101%

#include<stdio.h>
#include<conio.h>
#include<string.h>
#define MAX 100

void replace(char[],int);
int main()
{
    char str[MAX]="Brendon Mccullum smashes a ball a long way!";
    int i=0;
    int flag=0;
    printf("\nEnter a string: ");
    gets(str);
    printf("\n%s",str);

    
    while(str[i]!='\0')
    {
          flag=0;
          if(str[i]=='a')
          {
                         if((str[i-1]==' ' && str[i+1]==' ') || (str[i-1]==' ' && str[i+1]=='\0'))
                             flag=1;
          }
          if(flag==1)
          {
                     //printf("\nThe value of i should be 9. It is %d", i);
                     replace(str,i);
          }
          i++;
    }
   
    getch();
    printf("\n%s",str);
    getch();
    return 0;
    
}

void replace(char a[],int pos)
{
     int i=1,j=0,k=0,l=1;
     //printf("\n%c",a[pos+2]);
     j=strlen(a)-1;
     //printf("\n%d",j);
     a[j+3]='\0';
     k=j-pos;
     for(i=j,l=1;l<=k;i--,l++)
     {
          //printf("\nIt does work fine till here");
          a[i+2]=a[i];
          //printf("\nHere??? %d",i);
          //getch();
     }
     a[i]='t';
     a[i+1]='h';
     a[i+2]='e';
}

- Sachin Tendulkar's devotee April 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//Making a new string << not changing the actual one >>
//Pesudo code for going in O(n) time and O(n) memory
1. Count No. of single 'a' in the string in O(n).
2. Allocate newstring = strlen(string)+3*num_of_a memory
3. Now scan the string from left and on coming of a put the and continue till end

- Mohit Nagpal April 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Solution in python:

'''Replace all single occurrences of "a" with "the" (See question posted by Troy on Oct 7 2010)'''
def replace(str):
    
    i = 0
    res = ""
    for s in str:
        
        try:
            test_condition = str[i-1] == ' ' and str[i+1] == ' ' and s == 'a'
        except IndexError:
            pass    # ignore index out of range.
        
        if test_condition:
            res = res + 'the'
        else:
            res = res + s
            
        i = i+1
        
    return res
    
string = "This is not a town we were looking for; this is an apple orchard"
print replace(string)
# output: This is not the town we were looking for; this is an apple orchard

''' regex solution. achieves the same thing.'''
import re
re.sub(r'\ba\b', 'the', string)

- AnnoyingAnon April 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hmm.. seems like some of you guys did not even run your code to check its correctness..

class Main
{
    public static void main(String[] args) throws java.lang.Exception {
        String input = "This is not a town we were looking for; this is an apple orchard";
        String result = "";
        java.util.StringTokenizer st = new java.util.StringTokenizer(input);
        
        while (st.hasMoreTokens()){
            String curr = st.nextToken();
            if (curr.equals("a") ) {
                result += "the";
            } else {
                result += curr;
            }
            if (st.hasMoreTokens()){
                result += " ";
            }
        }
        System.out.println(result);
    }
}

- AnnoyingAnon April 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="" line="1" title="CodeMonkey54817" class="run-this">#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>

using namespace std;

int main(){
string line;
getline(cin,line);
istringstream iss(line);
string result="";
while(iss){
string sub;
iss>>sub;
if(sub!=""){
if(sub == "a"){
result+="the ";
}
else
result+=sub+ " ";
}
}
cout<<result<<endl;
return 0;
}</pre>

- einstein010 April 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main() {
int count = 0;
string str;
cout<<"Enter the string: ";
getline(cin,str);
string str2 = "the";
string :: iterator it;
cout << "Original String is: " << str;
for(unsigned int i=0;i<str.length();i++){
if(str[i]=='a'){
count++;
str.replace(i,1,str2);
}
}
cout<<endl;
for (it=str.begin(); it<str.end(); it++){
cout<<*it;
}
cout<<endl;
cout<<"number of 'a' occurrences are: "<<count<<endl;
return 0;
}

- Shekhar Agrawal June 30, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Read the Question; specifically prohibits use of inbuilt replace function for string manipulation.

- mzikit July 18, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can I use java StringBuilder insert function

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

int main()
{
string s = "I is a bad to do a work a";
string temp = "";
for(int i = 1; i < s.length();i++)
{
if(s[i-1] == ' ' && s[i] == 'a' &&
(s[i+1] == ' ' || s[i+1] == '\0'))
{
temp = temp + s.substr(0,i);
temp = temp + "the";
s = s.substr(i+1,s.length());
i = 1;
}
}
temp = temp + s;
cout<<temp;
}

- knoweth October 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*Replace all single occurrences of "a" with "the"*/
#include<stdio.h>
#include<iostream>
#include<string.h>

using namespace std;

int main()
{
string str="I am a spiderman.";
unsigned int i,count=0;
//getline(cin,str);
string ch="a";

for(i=0;i<str.length();i++)
{
if(str[i]=='a')
count++;

}

cout<<count<<endl;

//while count,find index of i and replace

size_t found;

while(count)
{
found=str.rfind(ch);
if (found!=string::npos)
str.replace (found,ch.length(),"the");

count--;
}
cout<<str<<endl;


//system("PAUSE");
return 0;
}

/*h t t p://codepad.org/zPETqIWO*/

- uber_geek December 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*Replace all single occurrences of "a" with "the"*/
#include<stdio.h>
#include<iostream>
#include<string.h>

using namespace std;

int main()
{
string str="I am a spidermanaaci.";
unsigned int i,count=0;
//getline(cin,str);
string ch="a";

for(i=0;i<str.length();i++)
{
if(str[i]=='a')
count++;

}

cout<<count<<endl;

//while count,find index of i and replace

size_t found;

while(count)
{
found=str.rfind(ch);
if (found!=string::npos)
str.replace (found,ch.length(),"the");

count--;
}
cout<<str<<endl;


//system("PAUSE");
return 0;
}

- uber_geek December 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

this works i compiled it
int main()
{
char input[400],output[400];
int c=0,j=0,b=0;
cout<<"\n Enter string to replace 'A' with 'THE'\n";
cin>> input;
while (input[c] != '\0')
{

if (input[c] == 'a')
{
output[j]='t';
output[j+1]='h';
output[j+2]='e';
j+=3;

}
else
{
output[j]= input[c];
j++;
}
c++;
}
cout<<output;

return 0;
}

- sameershah21 December 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class aReplacement 
{

	public static String sentence = "A parrot alone in the cage is eating a fruit";
	public static String str[];
		
	public static void main(String[] args) 
	{
		str = sentence.split(" ");
		for(int i=0;i<str.length;i++)
		{
			
			if(str[i].matches("a") || str[i].matches("A") )
			{
				str[i] = "the";
			}
			
			System.out.print(str[i]+" ");
		}

	}

}

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

{
$input = $_POST['name'];
$output = strtr( $input , array ('a' => 'the'));
print $output;
}

- Justin March 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*
* Replace all single occurrences of "a" with "the"
*/
public class epic_OA_replaceAwithThe {
public static String replace (String input) {

String[] inputSplit = input.split(" a");
input = inputSplit[0];
for(int i=1; i<inputSplit.length; i++) {
input += " the"+inputSplit[i];
}

return input;
}

public static void main(String[] arges) {
System.out.println(replace("This is a English nove, which is a magic"));
}
}

- sduwangtong October 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.*;

public class Test{
   public static void main(String args[]){
     String input = "This is a sentence in English";
String[] inputSplit = input.split(" a ");
input = inputSplit[0];

for(int i=1; i<=inputSplit.length-1; i++) {
   input += " the "+inputSplit[i];
}
System.out.print(input);
   }
}

- Anonymous January 31, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

i=-1;
while(source_string[++i]!="\0")
{
if(string[i]!="t")
  continue;
else
{
  if(string[i+1]!="h")
    continue;
  else
  {
    if(string[i+2]!="e")
      continue;
    else
      {
        j=i;
        source_str[j]="a";
        while(source_str[++j+2]!="\0")
          source_str[j]=source_str[j+2];
        source_str[j]=source_str[j+2];
      }
  }
}
}

- Shane.Y.Fang December 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

But it doesn't work for strings other than "a" and "the". Can anyone tell how to code for all strings?

- Anonymous December 07, 2010 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

public class athe {

	public static void main(String[] args) {
	   String str="I am a pretty apple";
       String newstr=str.replace(" a "," the ");
       System.out.print(newstr);
	}

}

- disun March 11, 2013 | 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