Microsoft Interview Question for Software Engineer / Developers






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

As per my understanding, 3rd no. from list means from the remaining list. Also we cant consider it as circular list. Let me know my understanding is correct or not.

- DD March 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

}
 
bool willExist ( int X ,int p )
{
     int k=2;
     
     while( k<=p && k<=X )
      {
           if( ! (X % k )  )
            return false;
         
             X-=X/k;
            
             k++ ;
              
              }   
              
      return true;
      
      }

- @^ March 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sorry ! made a mistake in the above post .

bool willExist ( int X ,int p )
{
     int k=2;
     
     while( (k-1)<=p && k<=X )
      {
           if( ! (X % k )  )
            return false;
         
             X-=X/k;
            
             k++ ;
              
              }   
              
      return true;
      
      }

- JD March 23, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If we remove the elements from the fixed list(removed positions are not filled by next index) then if suffices to check if
for 1<i<=p , i is a factor of N. If so it will not exist. Thus prime numbers will never be removed if they are > p.

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

It's a sieve process, but it doesn't produce prime numbers.

- Anonymous March 23, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think the condition is for 1<i<=p+1 , i is a factor of N.

- karthick March 25, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ques:whether n th number exist after p passes?(not a circle list)
Ans:
Simply, we only need p times check, one check for each pass.
int i=1;
//t means that every t th number is removed for current pass
int t=2;
for(;i<=p; ++i, ++t)
{
if(n%t==0)
return true;
n=n-n/t;
if(n<0)
return false;
}
/**********explanation*************
*make the input position n as our judging position
*after each pass, we update its new postion by n=n-n/t;
*because each pass, we remove n/t values before it
*if n%t equals to 0, it will be removed at current pass
*after updating n , that if n is below 0
*then it can exist for ever, since later pass will not remove it
***********************************/

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

sorry, my algorithm 's returned value(true or false) are opposite.

- lyzoridc March 28, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

thanks for the idea. it doesnt work for n=7, p=4. Here is a modified version

bool doesExist(int n, int p)
{
	//Simply, we only need p times check, one check for each pass.		
	//t means that every t th number is removed for current pass	
	for(int i=1, t=2;i<=p; ++i, ++t)
	{
		if(n%t==0)
			return false;

		n=n-n/t;
		if(n<0)
	 		return true;
	}
	return true;
}

- e=mc2 April 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Check whether the numbers are Co-Prime or not

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

Actually this is the efficient way to find out the prime numbers
so We will be left only with the prime numbers

- erappy July 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We are left with prime numbers greater than p+1
and also all numbers which can be factored into powers of primes such that all primes are greater than p+1;
above observation comes from ques.

- amit July 16, 2010 | 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