You are on page 1of 2

P1. Given a 2D array, print it in spiral form.

Input:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Output:
1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10

Input:
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
Output:
1 2 3 4 5 6 12 18 17 16 15 14 13 7 8 9 10 11
P2. Given k sorted arrays of size n each, merge them and print the sorted output
.
Input:
k = 3, n = 4
arr[][] = { {1, 3, 5, 7},
{2, 4, 6, 8},
{0, 9, 10, 11}} ;
Output: 0 1 2 3 4 5 6 7 8 9 10 11
P3. Given a binary matrix, print all unique rows of the given matrix.
Input:
{0, 1, 0, 0, 1}
{1, 0, 1, 1, 0}
{0, 1, 0, 0, 1}
{1, 1, 1, 0, 0}
Output:
0 1 0 0 1
1 0 1 1 0
1 1 1 0 0
P4. Calculate square of a number without using *, / and pow() . (Don't use r
epeatative addition)
Input: n = 5
Output: 25
P5. Given an integer x , write a C function that returns true if binary representat
ion of x is palindrome else return false.
Input: x = 27
Output: True (27 == '11011')
Input: x = 10
Output: False (10 == '1010')
P6. Given a sequence of moves for a robot, check if the sequence is circular
or not. A sequence of moves is circular if first and last positions of robot ar
e same. A move can be on of the following.
G - Go one unit
L - Turn left
R - Turn right
Examples:
Input: path[] = "GLGLGLG"
Output: Given sequence of moves is circular
Input: path[] = "GLLG"
Output: Given sequence of moves is circular
P7. We are given a string having parenthesis like below
( ((X)) (((Y))) )
We need to find the maximum depth of balanced parenthesis, like 4 in abo
ve example. Since Y is surrounded by 4 balanced parenthesis.
If parenthesis are unbalanced then return -1.
More examples:
S = "( a(b) (c) (d(e(f)g)h) I (j(k)l)m)";
Output : 4
S = "( p((q)) ((s)t) )";
Output : 3
S = "";
Output : 0
S = "b) (c) ()";
Output : -1
S = "(b) ((c) ()"
Output : -1
P8. Given two rectangles, find if the given two rectangles overlap or not.
Note that a rectangle can be represented by two coordinates, top left an
d bottom right. So mainly we are given following four coordinates.
l1: Top Left coordinate of first rectangle.
r1: Bottom Right coordinate of first rectangle.
l2: Top Left coordinate of second rectangle.
r2: Bottom Right coordinate of second rectangle.

You might also like