Citrix System Inc Interview Question


Country: India




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

all odd no. will be removed in 1st iteration
...
let say for a give no. X=45465454154654 i.e even and itr be the iteration upto which we have to say it will be removed or not
then

for (n=1;n<=itr;n++)
{
     for(z=1;X>2n(1+3z);z++)
{
                       if X%(2.n(1+3z))==0;
                          print"removed  in"+ nth +"iteration";
}
}

- shreyans June 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

What is the logic for getting this formula 2n(1+3z) ?


Please always explain fully the logic you are following and then write code...just writing code does not helps the cause.

- Nitin Gupta June 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Does it not fail for X = 1 ,2 ,3 . The minimum it needs is 8. for(z=1;X>2n(1+3z);z++).

Minimum value of 2n(1+3z) is 8 (for n =1 and z =1 ).

- Codelearner June 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@: nitin 
in 1 st iteration all odds are removed 
so 1 , 3, 5, 7...... are not to be considered
for any no of itertions they would have been removed
now after 1 st iteration we have

2 4 6 8 10 12 14 16
in 2nd we remove every 3 rd no.

means.... 2(1+3.x) where x varies from 0 to some no.
    like 2 8 14  ....

now after 2 nd iteration left are

4 6  10 12  16 18  22  24   28.....
 in 3 rd we remove every 4 th element
so we remove 4(1+3x) where x from 0 to some no.
eg...4  16   28.....
..
is that clearn now for every nth iteration 
2(n-1)(1+3x) where x from 0 to some no.

- shreyans June 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@: code learner sorry dear

from 0 to ......some no.

and about the odd no.'s those are removed in the very 1 st iteration 
the code i submitted is for checking even no..
is that k

- shreyans June 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

In the 4th iteration ,it will eliminate 42 , which should not get eliminated.

- codelearner June 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

actully the 4 th iteration is the 5 th one becoz the first iteration is to eliminate the alternate that is odd no..
and 2n (1+3x) for n=4 and x=1 it removes 32 and x=2 it removes 56 
and not 42

- shreyans June 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Dude your algo will work fine uptil n < 4 after than it will screw things up.
Lets take a look what numbers your code is removing for first five loops.
1. 8, 14, 20, 26..
2. 16, 28, 40, 52..
3. 24, 42, 60, 78..
4. 32, 56, 80, 104..
5. 40, 70, 100, 130..

what it should remove is these numbers.
1. 2, 8, 14, 20...
2. 4, 16, 28, 40...
3. 6, 24, 42, 60...
4. 10, 36, 62, 88... and (voila).

for quick just take x = 10, itr = 4, u will understand that it's not
printing anything.

- Sanjay Singh August 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

#include<stdio.h>
#include<stdlib.h>

using namespace std;

int ceil(int n,int i)
{
	if(n%i == 0)
		return (n/i);
	return (n/i + 1);
}

int main()
{
	int i = 2;
	int N,n;
	scanf("%d",&N);
	n = N;
	while(1)
	{
		if(n%i == 1)
		{
			printf("\n%d is removed in %d iteration\n",N,i-1);
			break;
		}
		n = n-ceil(n,i);
		i++;
	}
	return 0;
}

Explanation: Thing to understand here is that how does position of a number in the list change from (i-1)th iteration to i th iteration.

If a number is in nth position in (i-1)th iteration and n%i == 1 then it is deleted in i-1 th iteration otherwise ceil(n/i) numbers less than it have been removed and its position in next iteration is n - ceil(n/i).

- kunal10 June 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

NIce Solution!

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

find out the number of iteration to delete 8.
after first iteration you will left with 2, 4,6,8,10,12,14,.......
after 2nd iteration : 4,6,10,12,.....

means 8 is deleted in 2nd iteration. but your solution doesn't suffice this.

please make clear if i am wrong. Thanks

- goldi October 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

"You have a number written starting from 1 to infinitive"
Please be clear, whether its a single number containing numbers written from 1 to infinitive
or a list of numbers from 1 to infinity

- alexander June 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@spider:
Could you provide us with an example to make your question more clear

- Begineer June 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
int x,y,z,w;
scanf("%d", &x);
y=(int)sqrt(2*x);
if(((y*(y+1)/2)+1)<=x);
else y=y-1;

z= (y*(y+1)/2)+y;

w=z-y-1;
if(x>=w && x<z)
printf("not deleted");
else
printf("deleted");
getch();
}
complexity O(1)

- shagun June 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry i got d question wrong...dis is an answer if question wud b removing only 1 element in an iteration

- shagun June 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

i guess this r lucky numbers....we jst have to find new position of an elemnt after every iteration if position become less than current iteration the num will never get deleted......

- shivi116 June 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

dude every no. will be deleted some how

worst case is its deleted when it comes to first index.

- shreyans June 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Isnt this the famous 100 locker puzzle?


The school has 100 lockers. One by one each student has to go the lockers and open them in the following pattern:
Student 1 opens all the lockers
Student 2 goes and closes every second locker
Student 3 goes and "changes the state" of every third locker i.e. if its open , close etc and vice versa.
Student 4 changes the state of every 4th locker.
.
.
.
.Student n changes the state of every nth locker
This goes on for all 100 students.

They have to tell which all lockers are open at the after 100th student is done with his task.

- bhaskar.jain2002 June 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Remaining number after t iteration = n - floor(n/t) - n%t ;
Where n is the number of digits in number
So we have to solve this equation for t=1,2,3,.....

- Guru June 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Please can you elaborate more on your approach

- Anonymous June 26, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

cant understand.. n is stand for?? plz elaborate more

- spider June 26, 2012 | Flag


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