Saturday, January 24, 2015

National Instruments Interview Experience, SE - Set 1



I recently had a online written test with National Instruments, Bangalore.
I am sharing the questions here:


Q.1. Minimum difference pairs

You are in the data analysis business. One of your clients needs some analysis done on her company's stock values. She has set of values which represent the change in the stock values in a single day trade over a period time. A positive value represents that the stock value was higher when the market closed compared to when the market opened on the particular day. A negative value represents fall in the stock value on the particular day. A zero implies the stock price was unchanged.

For a given set of such values, she wants to figure out what is the minimum difference between any two values in that set and the count all the pairs whose difference is equal to the minimum difference.

You will given the count of values n ( 1 <= n <= 105 ), followed by n integers Si ( -106 <= Si <= 106 ). You are expected to output the minimum difference d and the number of pairs p, where the difference is d.

Examples:
Inputs:
i)8
3 4 5 6 8 9 3 2

ii) 7
2 4 5 6 9 17 99

Outputs:
i) The minimum difference is 0, and there is only one pair of 3,3; the output will be:
0 1

ii) The minimum difference is 1, and there are two such pairs 4,5 and 5,6; the output will be:
1 2




Q.2. Skynet

Skynet has grown to become the dominant force on earth and has almost completely wiped out the human race. Skynet has been building robots ever since it's inception and has been updating it's models every year while making them better. Skynet wants to annihilate humanity completely. It plans to remove one last band of humans lead by John Connor. Skynet thinks it can destroy these humans using only two of it's robots. But Skynet doesn't want to send two robots with the same model number lest John Connor finds out a weakness in that model and easily destroy both of them.

Skynet has at its disposal N robots and to save space Skynet has stored information about pairs of robots belonging to the same model. If it doesn't have any info stored for a particular robot then it is implied that the robot is the only one in that model.

Given these constraints, in how many ways can Skynet pick two robots to destroy John Connor and his rag tag group of humans.

Inputs
N - Total number of robots. Each robot is assigned a number from 0 to N-1 (2 <= N <= 100000)
P - Number of pairs for which Skynet has information (2 <= P <= 100000)
This is followed by P pairs. Each pair has two numbers P1 and P2 each where 0<=P1<=N-1 and 0<=P2<=N-1 and P1 != P2

Output
Number of ways in which Skynet can select 2 robots such that both the robots are different models.

Example Input:
4 2
0 1
2 3

Example Output:
4

Explanation:
Here robots 0 and 1 are of one model, say model A. And 2 and 3 are of another model, say B. Therefore the total number of 
possibilities of picking 2 robots such that no two robots are of the same model are - (0, 2), (0, 3), (1, 2) and (1, 4) = 4

10 4
2 8
1 3
0 2
5 8
output : 38

10 5
5 4
8 0
1 9
2 1
0 2
output : 34


If you have any interview experience to share, feel free to reach us at codingtonic@gmail.com



No comments :

Post a Comment