Epic Systems Interview Question Software Engineer / Developers

  • epic-systems-interview-questions
    0
    of 0 votes
    9
    Answers

    get a string(word) from user, then make every possible permutation words.
    Ex)intput: tree => output : tree, rtee, rete, reet, etre, eetr, eert, eter, eret, teer, reet...

    - SuperK on December 12, 2011 in United States Report Duplicate | Flag
    Epic Systems Software Engineer / Developer

Country: United States
Interview Type: Written Test


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

here is the recursive code

#include <cstdlib>
#include <iostream>

using namespace std;


/* Function to swap values at two pointers */
void swap (char *x, char *y)
{
    char temp;
    temp = *x;
    *x = *y;
    *y = temp;
}

void permute(char *a, int i, int n)
{
   int j;
   if (i == n)
     printf("%s\n", a);
   else
   {
        for (j = i; j <= n; j++)
       {
            
                 if (a[i] == a[j] && i != j)
                continue;

          swap((a+i), (a+j));
          permute(a, i+1, n);
          swap((a+i), (a+j)); //backtrack
       }
   }
} 


int main(int argc, char *argv[])
{
    
    char a[] = "ABC";
    permute(a, 0, 2);
    system("PAUSE");
    return EXIT_SUCCESS;
}

- getjar.com/todotasklist my android app on December 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You need to use a "set" to eliminate the duplication in the case of "tree".

- Anonymous on December 30, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

you also can use next_permutation to eliminate the repeated output, but it needs to sort array first

vector<char> v;
sort(v.begin(), v.end());
do {
   // output elements in v
} while (next_permutation(v.begin(), v.end());

- seek on January 17, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This was very helpful. I spent a couple hours breaking my head trying to figure out what the code is doing. And it just blew me. This program is also careful not to print duplicates. Thanks!!

Just an improvement to save some unnecessary swap function calls. Call the swap function only if i is not equal to j. This holds for both the forward swap and the backtrack swap.

if ( i != j ) {
      swap ( a + i , a + j ) ;
}

- ranechabria on July 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="" line="1" title="CodeMonkey7469" class="run-this">class Perm {
static void p(char[] text, int i){
if (i==text.length)
System.out.println(text);
else for (int j=i;j<text.length; j++){
swap(text, i, j);
p(text, i+1);
swap(text, i, j);
}
}
static void swap(char[] text, int i, int j){
char c = text[i];
text[i]=text[j];
text[j]=c;
}

public static void main(String[] args) throws Exception{
p("tree".toCharArray(), 0);
}
}

</pre><pre title="CodeMonkey7469" input="yes">
</pre>

- Anonymous on December 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int Mycount = 0;

void permute(int n , bool *isVisited, int level, string crtString)
{
    if(level == n)
    {
        Mycount++;
        cout<<crtString<<endl;
    }
    else
    {
        for(int i = 0 ; i < n ; ++ i)
        {
            if(isVisited[i] == 0)
            {
                isVisited[i] = 1;
                char tmp = i + '0';
                permute(n, isVisited, level+1, crtString+tmp);
                isVisited[i] = 0;
            }
        }
    }   
}   

int main (int argc, const char * argv[])
{
    int n = 5;
    
    bool *isVisited = new bool[n];
    
    for(int i = 0; i < n ; ++ i )
    {
        isVisited[i] = 0;
    }
    
    permute(n, isVisited, 0, "");
    
    cout<<"count = "<<Mycount<<endl;
    
    return 0;
}

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

String text="tree";
char[] perm = text.toCharArray();
System.out.println();
int count=0;
int charLength = perm.length;
Set<String> set = new HashSet<String>();
while(charLength!=0){
charLength--;

for (int j = 0,i=1; j <perm.length-1; j++,i++) {

if(i!=j){
char temp = perm[j];
perm[j]= perm[i];
perm[i] = temp;
String x = new String(perm);
// System.out.println(x);
set.add(x);
// count++;
}
else{
System.out.println("i==j");
}

}


}
Iterator<String> it = set.iterator();
while(it.hasNext()){
count++;
System.out.println("Perm WOrds Are : "+it.next());
}
System.out.println("Total "+count);
}

- Sanjay on December 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what a joke !

- Anonymous on December 13, 2011 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

fsdf

- dsf on December 21, 2011 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book walking you through every aspect of getting a job at a top tech company, while focuses on software engineering interviews.

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