Expedia Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

youtube, v=uPYhYVeXYxM

- Sai Nikhil November 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

public void swap(char[] a,int  x,int y)
		{
			char temp = a[x];
			a[x] = a[y];
			a[y] = temp;
		}
		
		
		public void permutation(char[] a,int left,int right)
		{
			if(left == right)
			{
				for(int i = 0;i < sizeOfArray;i++)
				{
					System.out.print(a[i] + " ");
				}
				System.out.print("\n");
			}
			else
			{
				for(int currentPos = left;currentPos <= right;currentPos++)
				{
					swap(a,left,currentPos);
					permutation(a,left+1,right);
					swap(a,left,currentPos); //Backtracking !
				}
			}
		}

- Buzz_Lightyear November 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A intuitive recursive approach:

public static ArrayList<String> permutations(String str) {	
		ArrayList<String> result = new ArrayList<String>();
		
		int length = str.length();
		switch(length) {
		case 0:
			break;
		case 1:
			result.add(str);
			break;
		case 2:
			result.add(str);
			String rstr = new StringBuffer(str).reverse().toString();
			result.add(rstr);
			break;
		default:
			for (int i = 0; i < length; i++) {
				String remaining = new StringBuffer(str).deleteCharAt(i).toString();
				for (String sub_permutation : permutations(remaining)) {
					String s = str.charAt(i) + sub_permutation;
					result.add(s);
				}
			}
			break;
		}
		
		return result;
	}

Basically for a string "asdf", it first takes 'a' and prepends it to each of the permutations("sdf"), next, it takes 's' & prepends to permutations("adf"), and so on.

Note however that it soon begins to use a lot of memory, and will fail when the string length is more than 10 charecters.

- LikhitD November 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

main()
{char ch[2],temp;
int i,k=1,b,f;
printf("enter the string");
gets(ch);
for(i=1;i<=strlen(ch);i++)
{ k=k*i; }
f=strlen(ch);
for(i=0;i<k;i++)
{ b=i%(f-1);
printf("%s\n",ch);
temp = ch[b+1];
ch[b+1]=ch[b];
ch[b]=temp;
}

- kuldeep singh rana November 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

void swap(char *a, char *b)
{
   char tmp = *a;
   *a = *b;
   *b = *a;
}

void perm(char arr[], int n, int k)
{
  int i = 0;

  if ((k == n) || (n == 1)) {
     printf("%s\n", arr);
     return;
  }
  for(i = k; i < n; i++) {
    swap(&arr[i], &arr[k])
    perm(arr, n, k+1);
    swap(&arr[i], &arr[k]);
  }
}

int main()
{
   char arr[] = "manoj";
   perm(arr, strlen(arr), 0);
   return 0;
}

- Anonymous November 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

python version:

for i in {}.fromkeys(itertools.permutations("aba"), 0).iterkeys():
	print i

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

# ruby : print all permutations of a string
puts "abcd".chars.to_a.permutation.map { |c| c.join }

# remove uniques
puts ("aba".chars.to_a.permutation.map { |c| c.join }).uniq

- sean December 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

remove the repeat ones .

- nz2324nz2324 December 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

?. that should not produce dups. [edit] ahh. i see. if my string has repeated chars like your example "aba".

- sean December 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

that's it. Good job!

- nz2324nz2324 December 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

thanks! seems like quite a bit for one line, but it does the trick. :)

- sean December 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

void Permutation(string beginStr, string endStr)
{
if (endStr.Length <= 1)
{
Console.WriteLine(beginStr+endStr);
}
else
{
for (int i = 0; i < endStr.Length; i++)
{
Permutation(beginStr + endStr[i], endStr.Substring(0, i) + endStr.Substring(i + 1));
}
}
}

- Shuai December 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void permute(String str, int l, int r) {
                
                if(l == r-1) {
                        System.out.println(str);
                        return;
                } else {
                        for(int i=l; i<r; i++) {
                                swap(str, l, i);
                                permute(str, l+1, r);
                                swap(str, l, i);
                                
                        }
                }
                
                return;
        }
        
        void swap(String str, int l, int r) {

                char[] charArray = str.toCharArray();
                char temp = charArray[l];
                charArray[l] = charArray[r];
                charArray[r] = temp;
                str = new String(charArray);
        }

- Kapil July 13, 2017 | 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