Escolar Documentos
Profissional Documentos
Cultura Documentos
7) You are given the initial positions in the plane and the constant velocity vectors of two points. Write a
function to find the instant of time at which they meet - if they do - or return –1 if they don’t.
Input:
Position1 (1,1)
Velocity1 (1,2)
Position2 (2,3)
Velocity2 (-1,-2)
Output:
0.5
8) Write a function to find out if the given number is prime.
9) Consider an excel sheet filled in row major order with integers starting from 1. Given an integer, print it's
row number and column name (assume there are 256 cols in a row and they are named A, B...Z, AA,AB,AC...IV)
Input: 256
Output: 1 IV
10) Write a function that takes a binary tree’s root node as input and returns true if the tree is a chain of
nodes and false if it is not.
For the following tree, the output is false
1
\
2
/ \
3 4
Output is true for this tree
1
/
2
\
3
11) Given a number N, find the number of perfect squares smaller than or equal to that number.
12) Given an array with elements decreasing up to a point and then increasing, find the minimum value. (All
elements in array are distinct)
13) Write a function to remove the least significant set bit from a number.
Input: 15
Output: 14
Output:
Person 1: (4,1) (1,3)
Person 2: (4,4) (1,5)
3) Given an array, count the number of inversions in the array. An inversion is an unordered pair of indices in
the array (i,j) such that i < j and a[i] > a[j]
Input:
5
54321
Output:
10
4) Given an integer N, place N chess queens on an N x N board in such a way that no two queens threaten
each other. A queen can move any number of cells in all eight directions.
Input:
4
Output:
0100
0001
1000
0010
Here, a 1 indicates that the cell is occupied by a queen and 0 indicates an empty cell.
2) You are given an array of length N (1 <= N <= 10e5). This is followed by Q queries, each of which can be of
the following two types:
Type 1: i x (change element a[i] to x)
Type 2: L R (find the xor of all elements in the range [L...R])
3) You are given a graph with N nodes. Initially, no two nodes are connected. This is followed by Q queries.
Each query can be of the following two types:
Type 1: u v (add an undirected edge between nodes u and v)
Type 2: Find the number of nodes in the largest connected component