Java Interview Report
- 0of 0 votes
AnswerKingKong, the largest living ape, escaped from Xanadu lab into a forest. The forest is filled with dangerous animals, which will attack and kill human beings that venture too close to them. You are required to help the scientists find a way to get to KingKong safely. The table below gives the minimum distance one must keep from each species for safety.
- dev May 22, 2012 in United States
Animal Name
Code
Safety distance (unit cell)
Lion L 1
Panther P 2
Both, the animals as well as the scientists can move only in horizontal or vertical directions. So, in the figure, the cells shaded gray are the cells into which the scientists must NOT venture, in order to be safe. The arrow shows that the panther is one vertical and one horizontal (a total of two) cell away from it.
A snapshot of the forest is obtained from a satellite picture in terms of an MxN matrix, which is the input to your program. This snapshot gives the location of various animals in the forest. Some cells might contain trees, which merely block the path of the scientists. The cells within the snapshot are marked by:
Animal code indicating the animal present in the cell
'T' in case of a tree present in the cell
'S', which indicates the start position of the scientists
'K', KingKong's location
'#', All other cells, which are empty
The output of your program should be the number of steps in the path that the scientists should take.
Notes:
There will be a unique path, if one exists.
The entire path including the starting position of the scientist as well as KingKong's location must be safe.
Input specification:
The first line contains two integers M and N the number of rows and columns. The next M lines contain N characters from the set {'L', 'P', 'T', 'S', 'K', '#'} as explained above
Output specification:
An integer specifying the length of the path, from the starting position of the scientist, to KingKong's position both inclusive. If KingKong is not reachable safely, then output the integer '-1'.
Sample Input and Output:
Input:
7 6
TLT#PP
LL####
LL#K##
TT##TT
TT#TTT
T###TT
TTTSTT
Output:
7
Input:
11 9
LL#######
L##TTTTT#
LKTTTTTT#
####P#TT#
###PP#TT#
####P#TT#
######TT#
L##T##T##
T##T####S
T####T###
TTTTTTLL#
Output:
-1| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswersGiven a matrix of order M x N containing 1.s and 0's, you have to find the number of maximal squares that can be formed. A square is formed by grouping adjacent cells containing 1. A maximal square is one that is not completely contained within another square. Maximal squares that overlap partially are to be counted separately. Unit squares (length of side = 1) should be also counted.
- dev May 22, 2012 in United States
Note that squares are filled, i.e. they cannot contain 0.s.
Number of maximal square: 6
Input specification:
The first line consists of integers M and N, the number of rows and columns of the matrix.
0 < M and N <=40
Next M lines contain N characters from the set {0, 1}.
Output specification:
An integer representing the number of maximal squares that can be formed followed by a newline.
Sample Input and Output:
Input:
4 5
11001
11110
11011
11001
Output:
9
Input:
2 2
10
11
Output:
3| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswerDr. Alberquert invented the following three devices to set up a simple communication network:
- dev May 22, 2012 in United States
Synthesizer (S), which produces signals continuously and transmits (propagates / passes on) them to neighbouring cells but cannot receive signals.
Receiver (R), which can receive signals from neighbouring signal sources but cannot produce or propagate signal.
Transmitter (T), which is capable of both receiving signal from and transmitting signals to neighbouring cells. Transmitters also are NOT capable of producing signals.
These devices are laid in a matrix formation. Signals are propagated at the rate of one cell per time unit. The absorption rate of a receiver is unlimited and so also the transmission and absorption rate of a transmitter unlimited. For simplicity we shall ignore the exact nature of signals being produced and consider them uniform across sources. Devices on the extreme right side can also communicate with the extreme left hand side device present in the same row (see fig 2). Similarly a device on the extreme top can also communicate with a device at the extreme bottom if they are present in the same column.
Please Note:
Neighbourhood is a four cell neighbourhood, i.e, the neighbourhood of a cell is defined by cells to its NORTH, SOUTH, EAST and WEST (see fig 1).
All Synthesizers will start to produce signals as soon as the simulation begins.
There could be multiple Synthesizers in a matrix arrangement.
Your task is to write a program that would take a matrix containing devices and output the time at which each receiver/transmitter receives its first signal.
Input specification:
The first line has two integers M and N indicating the number of rows and columns of the matrix. 0 < M, N <= 20
M lines follow the first line. Each of these M lines contains N characters and a terminating new line. Each character is one of S, T or R.
Output specification:
The output should be a matrix of M rows with each row containing N integers separated by spaces indicating the minimum time required for the signal to reach the corresponding device. The output for cells containing Synthesizers is 0. For devices that never receive any signal, print -1.
Sample Input and Output:
Input:
3 4
SRTR
TTTT
TTTS
Output:
0 1 3 1
1 2 2 1
1 2 1 0
Input:
2 3
RTT
TTR
Output:
-1 -1 -1
-1 -1 -1| Report Duplicate | Flag | PURGE
Java