Epic Systems Interview Question for Software Engineer / Developers






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

ArrayList<String> permutationsOf(String s)
{
     ArrayList<String> result = new ArrayList<String>();
 if (s.length() == 1)
{ // base case
         // return a new ArrayList containing just s         result.add(s);
         return result;
     }
       else 
       {         // separate the first character from the rest
          char first = s.charAt(0);
           String rest = s.substring(1);
         // get all permutationsOf the rest of the characters          ArrayList<String> simpler = permutationsOf(rest);  // recursive step          // for each permutation,   for (String permutation : simpler) 
   { // extra work
     // add the first character in all possible positions, and             ArrayList additions = insertAtAllPositions(first, permutation);
            // put each result into a new ArrayList             result.addAll(additions);
         }
         return result;
     }
 }
private ArrayList<String> insertAtAllPositions(char ch, String s) 
{
     ArrayList<String> result = new ArrayList<String>();
for (int i = 0; i <= s.length(); i++)
{
         String inserted = s.substring(0, i) + ch + s.substring(i);
         result.add(inserted);
      }
     return result;
}

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

Isnt this just the simple Factorial question , tweaked slightly ??

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

This is kind of factorial question. But we need to print all the permutations of input number. Ex: if the input number is 123. Convert the integer to string(use toString method), Then pass the string to permutationsOf("123") method. There are 3! permutations of the number. The result is
123
213
231
132
312
321

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

Can anyone explain the algorithm to print all possible permutation for the given number
( write the function )

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

I would do the circular link list

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

How can one do with circular linked list? I think its impossible!

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

How can one do with circular linked list? It does not make sense.

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

// Integer_Permutation.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

void main()
{
	vector<int> iV;
	int num,first,f,second,s,third,fourth;
	cout<<"ENTER PASSWORD : ";
	cin>>num;
	first = num/1000;
	f = num%1000;
	second = f/100;
	s=f%100;
	third = s/10;
	fourth =s%10;
	
	
	iV.push_back(first);
	iV.push_back(second);
	iV.push_back(third);
	iV.push_back(fourth);

	cout << "ENTERED PASSWORD : ";
	copy(iV.begin(),iV.end(),ostream_iterator<int>(cout,""));
	cout <<endl;

	cout <<"ALL COMBINATIONS OF THE PASSWORD: \n\n";
	
	
	while(next_permutation(iV.begin(),iV.end()))
	{
		copy(iV.begin(),iV.end(),ostream_iterator<int>(cout,""));
		cout <<endl;
	}

	system("PAUSE");
}

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

#include "stdafx.h"
#include<conio.h>
#include<stdlib.h>
#include<time.h>

void swapString(char*, int, int);
void rotateString(char*, int);

int _tmain(int argc, _TCHAR* argv[])
{
char original[5] = {'1', '2', '3', '4', '\0'};
char buff[5] = {'1', '2', '3', '4', '\0'};
int i, j, rem, n=3;

/*printf("Enter a 4-digit password: ");
scanf("%s", buff);*/

printf("The 4-digit password is: %s\n\n", buff);

printf("The combinations are:\n\n[00] %s\n", buff);

for(i=1; i<24; i++)
{
rem = i%2;

if(i>5 && i%6==0)
{
rotateString(original, n);
printf("[%02d] %s\n", i, original);

for(j=0; j<=n; j++)
buff[j] = original[j];
}
else
{
switch (rem)
{
case 1:
swapString(buff, n-1, n);
printf("[%02d] %s\n", i, buff);
break;
case 0:
swapString(buff, n-2, n-1);
printf("[%02d] %s\n", i, buff);
break;
default:
break;
}
}
}

getch();

return 0;
}

void swapString(char *buff, int a, int b)
{
char temp = buff[a];
buff[a] = buff[b];
buff[b] = temp;
}

void rotateString(char *buff, int n)
{
int i;
char temp = buff[0];

//printf("------------------\n");
for(i=0; i<n; i++)
{
buff[i] = buff[i+1];
//printf("%s\n", buff);
}
//printf("------------------\n");
buff[n] = temp;
}

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

//n is password string converted to int

//In main
int n = int.parse(console.readline());
Console.writeline("Combination of given pwsd is " + pswdCombi(n);

//function
static int pswdCombi(int n)
{
int _c = 1;
for (int i = 1; i <= n.ToString().Length; i++)
{
_c*= i;
}

return _c;
}

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

this code doesn't take care of repeated numbers.

- karen July 16, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I have the permutation code running and I did it using recursive functions..

- Vamsi June 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can u post the code?

- karen July 16, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Lol Vamshi seems to be a stuck up prick

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

What if the password has repeated characters?

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

#include<iostream>
#include<string>

using namespace std;

void permute(string str,int start)
{
     int i;
     
     if(start==str.size()-1)
     cout<<str<<"\n";
     
        for(i=start;i<str.size();i++)
        {
         swap(str[i],str[start]);
         permute(str,start+1);
         swap(str[i],str[start]);
         
         }
         
         }

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

c'on guys...its pretty simple..use the following simple solution,

#include<iostream>
#include<string>
using namespace std;
void permute(string s, int i = 0) {
    if (i == s.size()) cout << s << endl;
    else for (int j = i; j < s.size(); ++j) swap(s[i], s[j]), permute(s, i + 1), swap(s[i], s[j]);
}

int main() {
    string t = "123";
    permute(t);

    return 0;
}

just 3 lines of code and we're done!

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

Very good code thanks dude

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

nice code! but it still doesn't deal with repeated numbers...

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

why do you need the second swap after permute(s,i+1)?

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

http://www.dreamincode.net/forums/showtopic112813.htm

this page will help us understand the above code!

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

This comment has been deleted.

- Administrator April 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

- xxx April 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<stdlib.h>
int a[]={1,2,3,4};
int p[4]={0};
void permute(int i)
{
        int j;
        int t;
        if(i<4){
                for(j=0;j<4;j++){
                        if(a[j]!=-1){
                                p[i]=a[j];
                                t=a[j];
                                a[j]=-1;
                                permute(i+1);
                                a[j]=t;
                        }
                }
        }
        if(i == 4){
                printf("\n");
                for(j=0;j<4;j++){
                        printf("%d",p[j]);
                }

        }
}
void main()
{
        permute(0);
}

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

#include<iostream>

void permute(char a[],int i,int j)
{
char temp;
int k=0;
if(i==j)
printf("String is %s\n",a);

else
{
for(k=i;k<j;k++)
{

temp=a[j-1];
a[j-1]=a[k];
a[k]=temp;



permute(a,i,j-1);


temp=a[j-1];
a[j-1]=a[k];
a[k]=temp;

}
}

}

int main()
{

char a[30];
printf("Enter value\n");
scanf("%s",a);

permute(a,0,strlen(a));

printf("Original String is %s\n",a);

system("PAUSE");
exit(0);

}





Change type of array to int

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

<pre lang="" line="1" title="CodeMonkey21254" class="run-this">/* The class name doesn't have to be Main, as long as the class is not public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
int v[] = {3,4,5,6,9};
int n = v.length;
permute(v, 0, n);
}

public void permute (int[] v, int start_index, int n) {
if (start == v.length - 1)
print(v, n);

else {
for (int i = start_index; i<n; i++) {
int tmp = v[i];
v[i] = v[start];
v[start] = tmp;
permute(v, start+1, n);
v[start] = v[i];
v[i] = tmp;
}
}
}

public void print (int[] v, int n) {
if (v != 0) {
for (int i = 0; i < n; i++) {
System.out.println(v[i]);
}
}
}
}

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

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

class perm {
	public static void password(char[] pass, int i) {
		if (i == pass.length)
			System.out.println(pass);
		else
			for (int j = i; j < pass.length; j++) {
				swap(pass, i, j);
				password(pass, i + 1);
				swap(pass, i, j);
			}
	}

	private 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) {

		password("1234".toCharArray(), 0);
	}
}

- sanjeev kaneria March 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hey, guys. I tried to take care of repeated numbers too hence I used HashSet().
Please leave comment if there is a better way or improvement.
Thank you

public static void main(String args[]) {
        int[] pw = {1,2,1,3,1};
        Arrays.sort(pw);
        combo(pw);
    }
    static void combo(int[] pw){
        combo(pw, 0, pw.length, new HashSet());
    } 
    static void combo(int[] pw, int num, int count, HashSet set) {
        if (count == 0) {
            if(set.add(num)){
                System.out.println(num);
            }
            return;
        }
        int[] temp;
        for (int i = 0; i < pw.length; i++) {
            temp = delete(pw, i);
            combo(temp, num * 10 + pw[i],count-1,set);
        }
    }

    static int[] delete(int[] pw, int skip) {
        int[] updated = new int[pw.length - 1];
        for (int i = 0, j = 0; i < pw.length; i++) {
            if (i == skip) {
                continue;
            }
            updated[j++] = pw[i];
        }
        return updated;
    }

- junpos June 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.ArrayList;
import java.util.List;


public class Permutations {

	public static void main(String[] args) {
		List<String> perms = getPerms("123");
		for(String a:perms) {
			System.out.println(a);
		}
	}

	static List<String> getPerms(String input) {
		List<String> permutations = new ArrayList<String>();
		if (input == null) {
			return null;
		} else if (input.length() == 0) {
			permutations.add("");
			return permutations;
		} else {
			String remainder = input.substring(1, input.length());
			List<String> words = getPerms(remainder);

			char first = input.charAt(0);
			for (String word : words) {
				for (int k = 0; k <= word.length(); k++) {
					permutations.add(insertCharAt(first, word, k));
				}
			}
			return permutations;
		}
	}

	private static String insertCharAt(char c, String word, int k) {
		String start = word.substring(0, k);
		String end = word.substring(k);
		return start + c + end;
	}
}

Output:
123
213
231
132
312
321

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

private static void password(int[] a){
		int[] word = new int[a.length];
		for(int i=0; i< a.length; i++){
			word[0] = a[i];
			print(word, 1, a, a.length-1);
		}
	}
	
	private static void print(int[] word, int pos, int[] a, int len){
		if(len == 0){
			for(int k=0; k<word.length; k++){
				System.out.print(word[k]);
			}
			System.out.println();
			return;
		}
		
		boolean[] flag = new boolean[a.length];
		
		for(int i=0; i<flag.length; i++){
			for(int l=0; l<pos; l++){
				if(word[l] == a[i]){
					flag[i] = true;
				}
			}
		}
		for(int j=0; j<a.length; j++){
			if(flag[j] != true){
				word[pos] = a[j];
				print(word,pos+1, a, len-1);
			}
			
		}
	}

- Anon October 02, 2014 | 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