Expedia Interview Question for Software Engineer / Developers






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

Asked to explain solution and sent code into email after phone interview

- zdmytriv March 10, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I've sent this:

int uniques(int * arr, int size) 
{
    if(size < 3) return size;
    
    int i = 0;
    int j = i + 1;
    
    short do_swap = 0;
    while(j < size) {
        if(do_swap) {
            if(arr[i] == arr[j]) {
                j++;
            } else if(arr[i] != arr[j]) { 
                i++;
                
                // swap
                int tmp = arr[i];
                arr[i] = arr[j];
                arr[j] = tmp;
                
                j++;
            }
        } else {
            if(arr[i] != arr[j]) {
                i++;
                j++;
            } else {
                do_swap = 1;
            }
        }
    }
    return (i + 1);
}

- zdmytriv March 10, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

i tried the below..i guess it might work as well

void unique(int a[] ,int len)
{
int i=0,j=0;
j=i+1;

while(j<=len)
{
if(a[i]!=a[j])
{
printf("%d\n",a[i]);
i++;j++;

}
else
{
while(a[i]==a[j])
{ j++; }
j=j+1;
i=j-1;

}

}

- sun March 11, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I don't know what Zd is doing for:
if(size < 3) return size;

Array would overflow in sun's code:
while(j<=len)
{
if(a[i]!=a[j])

j should be from 0 - len -1.

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

Here is the code:

int getUnq(int a[], int len)
{
if (len == 1)
return 1;
int i = 0;
int count = -1; // count of uniq element;
int unq = a[i];
bool skip = false;
do
{
i++;
if (unq != a[i])
{
if (!skip)
{
count++;
a[count]=unq; // save in a
printf("%d is unq!\n",unq);
}
unq = a[i]; // new element
skip = false;
if (i== len-1)// the last one
{
count++;
a[count] = unq;
printf("%d is the last unq!\n",unq);
}
}
else
skip=true;
} while (i< len -1);
return count+1;
}

int _tmain(int argc, _TCHAR* argv[])
{
int sortArr[] = { 1, 2, 2, 3, 3, 4, 5, 5, 6};
int unqCount = getUnq(sortArr, 9);
printf("array has %d unqs!\n",unqCount);
for (int i=0; i< unqCount; i++)
printf(" %d, ",sortArr[i]);
printf("are the %d unqs in the sorted array. \n",unqCount);
getchar();
return 0;
}

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

public class UniqueElements{
public static void main(String args[]){
int [] sortArr = {1,1,2,2,3,4,4,5,5,6,7,8,9,9,10,12,12};
int length = sortArr.length;
int [] newArr= new int[sortArr.length];

for(int i=0,j=1;i<length;i++){
if(sortArr[i]==newArr[j-1])
;
else{
newArr[j]=sortArr[i];
j++;
}

}
for(int k=0;k<sortArr.length;k++)
System.out.print(newArr[k]+" ");
}
}

- Abhishek Rai June 21, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void findUniqueInts(int[] a) {
int duplicate = 0;
for (int i=0; i<a.length; i++) {
if (i == a.length-2) {
if (a[i] != a[i+1]) {
System.out.print(a[i+1] +" ");
}
break;
} else if (a[i] == 0 && a[i] != a[i+1]) {
System.out.print(0+" ");
} else if (a[i] != a[i+1] && a[i] != duplicate) {
System.out.print(a[i]+" ");
} else {
duplicate = a[i];
}
}
}

- Raj September 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void findUniqueInts(int[] a) {
int duplicate = 0;
for (int i=0; i<a.length; i++) {
if (i == a.length-2) {
if (a[i] != a[i+1]) {
System.out.print(a[i+1] +" ");
}
break;
} else if (a[i] == 0 && a[i] != a[i+1]) {
System.out.print(0+" ");
} else if (a[i] != a[i+1] && a[i] != duplicate) {
System.out.print(a[i]+" ");
} else {
duplicate = a[i];
}
}
}

- Raj September 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static void findUniqueInts()
{
int[] a = { 1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 7, 8, 9, 9, 10, 12, 12 };
int duplicate = 0;

for (int i = 0; i < a.Length; i++)
{
if (i == a.Length - 2)
break;

if (a[i] != a[i + 1] && a[i] != duplicate)
Console.WriteLine(a[i] + " ");
else
duplicate = a[i];
}
}

- Meruzhan October 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static void findUniqueInts()
{
int[] a = { 1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 7, 8, 9, 9, 10, 12, 12 };
int duplicate = 0;

for (int i = 0; i < a.Length; i++)
{
if (i == a.Length - 2)
break;

if (a[i] != a[i + 1] && a[i] != duplicate)
Console.WriteLine(a[i] + " ");
else
duplicate = a[i];
}
}

- Meruzhan October 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void printUniqueElements(int[] a){
        for(int i=0, j=1; j<a.length;i++,j++){
            if((a[i] != a[j]) && ((j != a.length - 1) && (a[j] != a[j+1])))
                System.out.println(a[j]);
        }

}

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

public static void printUniqueElements(int[] a){
        for(int i=0, j=1; j<a.length;i++,j++){
            if((a[i] != a[j]) && ((j != a.length - 1) && (a[j] != a[j+1])))
                System.out.println(a[j]);
        }

}

- Bharat Paturi March 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void printUniqueElements(int[] a){
        for(int i=0, j=1; j<a.length;i++,j++){
            if((a[i] != a[j]) && ((j != a.length - 1) && (a[j] != a[j+1])))
                System.out.println(a[j]);
        }

}

- Bharat Paturi March 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void printUniqueElements(int[] a){
for(int i=0, j=1; j<a.length;i++,j++){
if((a[i] != a[j]) && ((j != a.length - 1) && (a[j] != a[j+1])))
System.out.println(a[j]);
}
}

- Bharat Paturi March 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sorry about the multiple posts... every time it ended up in an error so couldn't find out that is has been posted or not... Hope they will include a Delete button soon.. at least it will give us a way to delete unwanted posts like these...

- Bharat Paturi March 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Xor the elements will get unique number

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

This wont work if the array is like

{1, 2, 2, 3,4};

- Barani February 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sorry didtn't mean to comment on this post..

- Barani February 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hey bharath,

I think if the last element in the array is a unique element then your printUniqueElements method will not return that element.

eg, int[] a = { 1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 7, 8, 9, 9, 10, 11, 12 ,13,};

13 will not be printed.

in order to get it printed it should like the below

public static void printUniqueElements(int[] a){
for(int i=0, j=1; j<a.length;i++,j++){
if((a[i] != a[j]) && ((j != a.length - 1) && (a[j] != a[j+1])))
System.out.println(a[j]);
if(a[i] != a[j] && j == a.length - 1){
System.out.println(a[j]);
}
}
}

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

This wont work if the array is like

{1, 2, 2, 3,4};

- Barani February 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String args[]) {

uniqueTest u=new uniqueTest();
int[] a1 = { 1, 1, 1, 2, 2, 3 };
uniqueTest.printUniqueElements(a1);



for (int i = 0; i < a1.length; i++) {
if (i == 0) {
if (a1[i] != a1[i + 1]) {
System.out.println(a1[i]);
}
} else if (i < a1.length - 1) {
if (a1[i] != a1[i + 1] && a1[i] != a1[i - 1]) {
System.out.println(a1[i]);
}
} else {
if (a1[i] != a1[i - 1]) {
System.out.println(a1[i]);
}
}
}
}

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

public static void main(String args[]) {

int[] a1 = { 1, 1, 1, 2, 2, 3 };

for (int i = 0; i < a1.length; i++) {
if (i == 0) {
if (a1[i] != a1[i + 1]) {
System.out.println(a1[i]);
}
} else if (i < a1.length - 1) {
if (a1[i] != a1[i + 1] && a1[i] != a1[i - 1]) {
System.out.println(a1[i]);
}
} else {
if (a1[i] != a1[i - 1]) {
System.out.println(a1[i]);
}
}
}
}

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

#include <iostream>

void print_uniques(int a[], int len)
{
int i = 0;
int j = 1;
while (j < len)
{
if (a[i] != a[j])
{
i = j;
std::cout << a[j] << " ";
}
++j;
}
};

int main()
{
int arr[] = {INT_MAX, 1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 7, 8, 9, 9, 10, 11, 12 ,13};

int length = sizeof(arr) / sizeof(arr[0]);
print_uniques(arr, length);
return 0;
}

- hao.liu0708 November 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

# Print unique elements of an array

arr=[0,0,0,0,0,0,0,0,1,2,2,4,5,6,7,8,9,9]
size=len(arr)
newArr=[0]*size
count=0
lastDuplicate=""
for i in arr:
	
	if count<size-1 and arr[count] == arr[count + 1]:
			lastDuplicate=arr[count]		
	if arr[count]==lastDuplicate:
			lastDuplicate=arr[count]
	else:
		print arr[count]
	count = count + 1

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

static void Main(string[] args)
{
int[] array = new int[]{1,1,1,2,2,3,3,3};
ExtractUnique(array, array.Length);
}

private static void ExtractUnique(int[] array, int length)
{
int i = 0;
int j = 1;
while (i < length && j < length)
{
if (array[i] != array[j])
{
Console.WriteLine(array[i].ToString());
j++;
i = j - 1;
}
else if (array[i] == array[j])
{
j++;
}
}

Console.WriteLine(array[i]);
Console.Read();
}

- abhiik January 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
// TODO Auto-generated method stub
int a[] = { 1, 1, 2, 2, 4,4,8,9 };
printUniq(a);
}

public static void printUniq(int a[]) {
if (a != null) {
if (a.length == 2) {
if (a[0] != a[1]) {
//
}
} else {
int min = a[0];
int start = 0;
for (int i = 1; i < a.length; i++) {
if (a[i] > min) {
min = a[i];
if (i == (start + 1)) {
System.out.println("unique elem at " + start
+ " value " + a[start]);
}
if (i == a.length - 1) {
System.out.println("unique elem at last " + i
+ " value " + a[i]);
}

start = i;
}
}
}

}
}

- Anonymous October 08, 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