-->

Sapient Nitro Interview Solution Set -1

Posted by Admin on
Round 1 :
Written Round (Technical + Aptitude)


Round 2: (Technical Interview)

Que: What is the difference between C and C++?
C:-
1. It is a structured programming language.
2. It main focus on function and procedure.
3.Its main feature are pointer and pre-processor.
4.It follows top down approach. For eg:- it mainly focus on function and then combining them to make the complete program.

C++:-
1.It is a object oriented programming.
2.Follows an bottom to top approach.
3.Entire problem is divided as objects.
4.It is improved version of c language.
5.Main features are pointers,class.

Que: What is the difference between for and while loop?


                   for loop                                                             while loop                                        
Initialization , testing and incrementation are done in same line. Initialization , testing and incrementation are done in separate line.

Condition tested before executing body of the loop. Condition tested before executing body of the loop.

Que : Write a program to add two numbers without using + operator.


#include <stdio.h>

int main(void) {
       int a=5;
       int b=6;
       int sum;
       sum = a-(-b);
       printf("%d",sum);
       return 0;
}

Que :How do you reverse a string without using any looping and inbuilt functions?

If we are not allowed to use loop and built in function then we are only left with recursive function.


#include <stdio.h>
#include<string.h>
static int count=0;
void reverseString(char str[], int len)
{
       if(count>=len)
       {
              return ;
       }
      
       char temp=str[len];
       str[len]=str[count];
       str[count]=temp;
       len--;
       count++;
       reverseString(str,len);
}

int main(void) {
  
   char str[]="everybrickmatters";
   int len =strlen(str);
   reverseString(str,len-1);
   printf("%s",str);
   return 0;
}


Que : How many queues will you use to implement a priority queue?
Two queue are needed to implement the priority queue . One queue is needed to store the priority and the other queue is needed is store the data .

Que : Which data structure would you use to implement an heteregenous array?

ArrayList is the best data structure to store the heterogenous array in java.

Que :  You are given a match-box and two candles of equal size, which can burn 1 hour each. You have to measure 45 minutes with these candles. (There is no scale or clock). How do you do?

A candle has two end setting the fire to both the end of candle simultaneously burn the candle as twice as fast,hence burning time of a candle on setting fire on both the end is 30 minutes .

First lit the candle 1 at both the end and candle 2 at one end .

After 30 minutes candle 1 is completely burnt and candle 2 has burnt for 30 minutes .

Now lit the candle 2 at the both the end it will burn completely in 15 minutes .
Total Time = 30 minutes + 15 minutes = 45 minutes .

Que : You have eight balls: seven are the same weight, and one is heavier or lighter than the rest. Given a scale that only tells you which side is heavier, how do you find the heavy or lighter ball?

In this kind of question divide the balls in groups such that each group contain balls to certain power of 3 which is nearest to the total number of balls.

So in our problem we divide the balls in
2 group of 3 balls each say group A and B
1 group of 2 balls say group C .

Case 1) Compare group A and B . If the side with group A is lighter or heavier than the side of group B , then choose any 2 balls from group A and compare if one of them is heavier or light then that ball is the required ball otherwise the third ball (which we did not put on the balance) is the required ball.

Case 2) If group B is heavy or lighter then apply the same logic in case 1.

Case 3) If group A = group B , then compare the two balls of group C whichever ball comes out heavy or lighter that is the required answer. 
              
Que : Three friends rent a room for Rs.30 by paying Rs.10 each. The owner decides to give them a discount Rs.5 and gives it to the broker. The broker who a cunning man takes Rs.2. and returns one rupee to each of them. So the sum paid by each person would be Rs.9 which adds upto Rs.27 and the broker took Rs.2 ,so the total is Rs.29 where did that Re.1 go?

Ans :
In this interviewer just want to see your way of analyzing a problem . According to the question three men paid 27 rupees for the hotel room . And according owner they should have paid 25 rupees after the discount of 5 rupees . It means 27 - 25 = 2 rupees are left which are at cunning man hence nothing is missing.


Please comment if you like the above post or find any mistake .


No comments:

Post a Comment