Citrix Online Interview Question for SDE-2s


Country: India
Interview Type: In-Person




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

In java

public static int removeOccurances(int[] data, int key){
		if (data == null)
			return 0;
		int length = data.length-1;
		if (length < 0)
			return 0;
		for(int i=length; i>=0;i--){
			if(data[i] == key){
				data[i] = data[length]; // replacing occurrence with last element
				data[length--] = 0;	  //  replacing last element with 0	
			}
		}
		return length; // This is the size of array which has no occurrence of key element.
	}

- vcd April 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

unsigned int remove_key(unsigned int a[], unsigned int size, unsigned int key)
    {
    	unsigned int left = 0;
    	unsigned int right = size - 1;
    	
    	while( left < right )
    	{
    		while( left < size && a[left] != key)
    			left++;
    			
    		while( right >left  && a[right] == key )
    			right--;
    		
    		swap(a,left,right);
    	}
    	return right;
    }

- pshaikh.jobs October 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hey parvez ,

after removing all the occurrences of the number array size will be changed right...??

so need to accept size as a pointer so it will be reflect in the main ()...

- subhedarnikhil October 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

function is returing new size of array, all elements after "right" index are duplicate occurrences of "key".

- pshaikh.jobs October 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Your solution is correct. But it does not preserve the correct order.

- Psycho October 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nikhil,

"main" is not the only functions that can/does call other functions.

So your function signature is something like this it seems [you should have maybe said it in original question :) ]:

typedef unsigned int uint;

void removeit(uint a[], uint remelem, uint *size) 
{
	for( i=0; i<(*size); i++)
   		if( a[i] == remelem )
	      		a[i] = a[(*size)--   -1];
}

Psycho, he doesn't mention "stable" in the requirements.
Move onto next Q man.

- S O U N D W A V E October 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int* removeNumberFromArray(int number, int array[])
{
    int count = 0;
    int size = (sizeof(array)/sizeof(array[0]));
    int j= size - 1;
    for (int i=0; i< (size - count); i++) {
        if(array[i] == number)
        {
            while(array[j] == number)
            {
                j--;
            }
            array[i] = array[j];
            array[j] = '\0';
            j--;
            count++;
        }
    }
    return array1;
}

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

public static int RemoveAllOccurance_Suffle(int[] a, int key)
        {
            int left = 0;
            int right = a.Length - 1;
            int end = right;

            while (left <= right)
            {
                if (a[left] == key)
                {
                    a[left] = 0;
                    swap(a, left, end);
                    end--;
                }
                left++;

                if (a[right] == key)
                {
                    a[right] = 0;
                    swap(a, right, end);
                    end--;
                }
                right++;
            }

            return end;
        }

- Narendra June 27, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int RemoveAllOccurance_Suffle(int[] a, int key)
        {
            int left = 0;
            int right = a.Length - 1;
            int end = right;

            while (left <= right)
            {
                if (a[left] == key)
                {
                    a[left] = 0;
                    swap(a, left, end);
                    end--;
                }
                left++;

                if (a[right] == key)
                {
                    a[right] = 0;
                    swap(a, right, end);
                    end--;
                }
                right++;
            }

            return end;
        }

- narendra June 27, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.


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