Epic Systems Interview Question for Software Engineer / Developers






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

private static void reverse(char[] c) {
		reverse(c,0,c.length-1);
		
		int wordStart=0;
		for(int i=0;i<c.length;i++)
		{
			if(c[i]==' ')
			{
				reverse(c,wordStart,i-1);
				wordStart=i+1;
			}
			else if(i==c.length-1)
			{
				reverse(c,wordStart,i);
			}
		}
	}

	private static void reverse(char[] c, int i, int j) {
		if(i>=j)
			return;
		for(int k=i;k<=(i+j)/2;k++)
		{
			char temp=c[k];
			c[k]=c[i+j-k];
			c[i+j-k]=temp;
		}
	}

- Vir Pratap Uttam May 12, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Stick the letters of the words in a queue, and the words themselves in a stack.

- memo July 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

1-reverse all words in string
sihT si taerg

2-reverse the string
great is This

- running July 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nice one.

- memo July 30, 2011 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

String sentence = "This is great";
String words[] = sentence.split(" ");

for(int i=words.length; i<0; i++){
System.out.println(words[i]);
}

- mani January 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

dude small correction , for loop condition should be i>0 and i--not i<0 and i++

- xx April 12, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
void reverse(char a[], int i,int j)
{
     char temp;   
     
          while(i<j)
    {
              temp=a[i];
              a[i]=a[j];
              a[j]=temp;
              i++;
              j--;
              
              
              
    }
}

int main()
{
    char a[]="Hello World";
    
    int i=0;
    int j=strlen(a);
  
reverse(a,i,j-1);    
    printf("Reversed String is  %s\n",a);
       
       j=0;
       
       while(a[i]!='\0')
       {
              if(a[j]==' ' || a[j]=='\0')
              {
                   reverse(a,i,j-1);
                   i=j+1;
                   j=i;
              }
              else
              {
              j++;            
              }
       }    
                   
    printf("Reversed String is  %s\n",a);
                       
    
    system("PAUSE");
        
}

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

was this question asked at onsite interview or was it sent to you after the phone interview?

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

storing each word in linked list and then reversing that linked list is better .

- sasi November 19, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

using namespace std;

int main()
{
    string inp;
    vector<string> final;

    while(cin.get()!='\n')
    {
     cin>>inp;
     final.push_back(inp);                    
                        
    }  

    vector<string>::reverse_iterator ii;
    
    for(ii=final.rbegin();ii!=final.rend();ii++)
     cout<<*ii<<"\t";
     
system("PAUSE");
return 0;
    
}

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

something is wrong with your code

- Pawan February 28, 2019 | Flag
Comment hidden because of low score. Click to expand.
0
of 4 vote

JAVA CODE:-

Stack<String> stack = new Stack<String>();
		String sentence = "This is great";
		String words[] = sentence.split(" ");
		
		for(int i=0; i<words.length; i++){
			stack.add(words[i]);
		}
		
		while(!stack.empty()){
			System.out.println(stack.pop());
		}

- Shashank January 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

String sentence = "This is great";
String words[] = sentence.split(" ");

for(int i=words.length-1; i>=0; i--){
System.out.println(words[i]);}
}}

- r January 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<string.h>
main()
{ int i,j,l;
char str[59];
printf("Enter the string\n");
gets(str);
l=strlen(str);
for(i=l-1; i>=0; i--)
{ if(str[i]==' ')
{ for(j=i+1; j<l; j++)
printf("%c",str[j]);
printf(" ");

l=i;

}

if(i==0)
{ printf(" ");
for(j=0; j<l; j++)
printf("%c",str[j]);
}
}
}

- @123 August 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ReverseWords {
	
	public static void reverseWords(String words){
		if(words.length() == 0 || words == null){
			return;
		}
		String[] words_array = words.split(" ");
		for(int i=words_array.length - 1;i>=0;i--){
			System.out.print(words_array[i]+" ");
		}
		System.out.println();
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		reverseWords("This is a word");
	}

}

- Kevin February 20, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;


public class Reverse {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub

ArrayList<String> al = new ArrayList<String>();
System.out.println("Enter the String you want to reverse");
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);

String str = br.readLine();

StringTokenizer st = new StringTokenizer(str);

while(st.hasMoreTokens())
{

al.add(st.nextToken());

}

Collections.reverse(al);

for(int i=0;i<al.size();i++)

{

System.out.print(al.get(i));


}






}

}

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

void fun(char *s){
        char t[30];
        int n;
        if( sscanf(s,"%s%n",t, &n)  == 1) {
                s += n ;
                fun(s);
                puts(t);
        }
}

- Amit August 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is a working code in C++. Basically I have reversed the alphabets for each word and then finally reversed the entire string.

#include <cstdio>
#include <iostream>
#include <string.h>

using namespace std;

int main()
{
    char str[100], ch;
    int i, len, st, ub;
    scanf("%[^\n]s", str);
    len=strlen(str);
    cout<<"\n";
    st=0;
    for (i=0; i<len; i++)
    {
        if (str[i]==' ')
        {
            ub=i-1;
            while (ub>=st)
            {
                ch=str[st];
                str[st]=str[ub];
                str[ub]=ch;
                ub--;
                st++;
            }
            st=i+1;
        }
    }
    ub=len-1;
    while (ub>=st)
    {
        ch=str[st];
        str[st]=str[ub];
        str[ub]=ch;
        ub--;
        st++;
    }
    ub=len-1;
    st=0;
    while (st<=ub)
    {
        ch=str[st];
        str[st]=str[ub];
        str[ub]=ch;
        ub--;
        st++;
    }
    for (i=0; i<len; i++)
    {
        cout<<str[i];
    }
    cout<<endl;
    return 0;
}

- Meraj Ahmed November 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package p1;

import java.util.ArrayList;

public class reverse_string {
	public static void main(String args[])
	{
		String str="This is great";
		ArrayList ar=new ArrayList();
		int p=str.length()-1;
		for(int i=p;i>=0;i--)
		{   
			if(str.charAt(i)!=' ')
			{   
				ar.add(str.charAt(i));
			}
			if(str.charAt(i)==' ' ||i==0)
			{
				ar.add(' ');
				display(ar);
			}
			p=str.length()-i;
			
		}
	}
	static void display(ArrayList ar)
	{
		for(int i=ar.size()-1;i>=0;i--)
		{
			System.out.print(ar.get(i));
		}	
		ar.clear();
	}
}

- Davi_singh November 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Better use a stack,
here is a java program.

static String reverse(String str){

StringBuilder sb = null;
if(str != null){
sb = new StringBuilder();
String arr[] = str.split(" ");
if(arr.length <=1){
return str;
}
else{
Stack<String> stack = new Stack<String>();
for(String s : arr){
stack.push(s);
}
while(!stack.isEmpty()){
sb.append(stack.pop());
sb.append(" ");
}
}
}
return sb != null ? sb.toString() : null;
}

- Anshul Sharma February 22, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>

using namespace std;

#include<string>

using std::string;

#include<stack>

void main()
{
string input;
getline(cin, input);
stack<string>mystack;
int lastspace = 0;

for (int i = 0; i < input.size() ;i++)
{
if (input.at(i) == ' ')
{
mystack.push(input.substr(lastspace, i - lastspace));
lastspace = i+1;
}
else if (i == input.size() - 1)
{
mystack.push(input.substr(lastspace, i - lastspace + 1));
}
}
while (!mystack.empty())
{
cout << mystack.top() << " ";
mystack.pop();
}

system("pause");
}

- swcvictor March 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static void reverse(String string2) {

		String[] sstring = string2.split(" ");

		for (int i = sstring.length - 1; i >= 0; i--) {
			for (int j = sstring[i].length() - 1; j >= 0; j--) {
			System.out.print(sstring[i].charAt(j));
		}
			System.out.print(" ");
		}
	}

- thanga April 12, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main()
{
    string s;
    getline(cin,s);
    stack<int> st;
    for(int i=0;i<s.length();i++)
        st.push(s[i]);
    for(int i=0;i<s.length();i++)
       {
           s[i]=st.top();
           st.pop();
       }
    cout<<s;
    return 0;
}

- sreyask August 18, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;

/*given a sentence reverse the sentence but not words in it
 * 
 * for example I am a good boy - boy good a am I
 * you are not allowed to use any String functions
 * */
public class Solution {

	public static void main(String[] args) {

		String str = "I am a good boy";
		reverseSentence(str.toCharArray());
	}

	private static void reverseSentence(char[] charArray) {

		int len = charArray.length;
		List<String> list = new ArrayList<String>();
		int start = 0;
		for (int i = 0; i < len; i++) {
			if (charArray[i] == ' ') {
				String reverse = "";
				for (int j = start; j < i; j++) {
					reverse = reverse + Character.toString(charArray[j]);
				}
				list.add(reverse);
				start = i + 1;
			}
		}
		System.out.println(list);
		for (int i = list.size() - 1; i >= 0; i--) {
			System.out.print(list.get(i) + " ");
		}
	}
}

- Anonymous February 25, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hjghj

- ghj tyeij July 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hdjydsf jgfdgf{}

- ghj tyeij July 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
String str = "This is wipro";
String[] words = str.split(" ");
for(int i = words.length - 1; i >= 0; i--)
{
System.out.print(words[i] + " ");

}
}
o/p wipro is This

- Ravindra February 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
public static void main(String[] args) {
String str = "This is wipro";
String[] words = str.split(" ");
for(int i = words.length - 1; i >= 0; i--)
{
System.out.print(words[i] + " ");

}
}
o/p wipro is This
}

- Ravindra February 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

str = 'This is great'
   str = str.split()
   str.reverse()
   print ' '.join(str)

- Anonymous February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

dsadsadad

- Ganesh November 27, 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