Lunatic Server Solutions Interview Questions
- 0of 0 votes
AnswersConsider a university having a very big campus spread in acres of land. The university is undergoing computerization. All the departments (at-most 50) are to be connected to form the intranet of the university. You have to write a program, implementing Prims algorithm, which will suggest the network topology and also minimise the total length of cable for connecting all the departments. Input to the program will be names of all the departments and straight line distances between the departments (Only those pairs of departments between which cable can be laid will be given). Output of the program should be the minimum length of the cable required.
- dev June 12, 2012 in United States
Input specifications
The first line will contain 2 natural numbers, N and M, separated by a blank space. N indicated the number of departments in the university and M indicates the number of pairs of departments where the cables can be laid. The following M lines will specify the distances between M pairs of departments as dept1 dept2 distance Where dept1 and dept2 are names of the departments (maximum 20 characters) and distance is a positive integer (>0). Assume that the given distances between each pairs of departments will be unique and these M lines will contain atleast one pair for each department.
Output specifications
The first line of the output will be names of the departments as they are included in the solution separated by blank space. If two or more departments are included at a time then their names should be printed in the alphabetic order. The next line will be the minimum length of cable required to form the intranet, terminated with a new line character.
Sample Input/Output
input
7 10
physics chemistry 8
biology physics 9
biology office 15
chemistry office 4
chemistry sanskrit 5
sanskrit office 7
english office 16
english sanskrit 19
english cs 12
sanskrit cs 6
output
chemistry office sanskrit cs
physics biology english
44| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Software Engineer / Developer - 0of 0 votes
AnswersLunatic server solution got a project in which they have to make a intranet web campus.
- PriyaDarad June 06, 2012 in United States
so entry for software developer , company make this problem.
solution must be in java.
Consider a university having a very big campus spread in acres of land. The university is undergoing
computerization. All the departments (at-most 50) are to be connected to form the intranet of the university.
You have to write a program, implementing Prims algorithm, which will suggest the network topology and
also minimise the total length of cable for connecting all the departments. Input to the program will be
names of all the departments and straight line distances between the departments (Only those pairs of
departments between which cable can be laid will be given). Output of the program should be the minimum
length of the cable required.
Input specifications
The first line will contain 2 natural numbers, N and M, separated by a blank space. N indicated the number
of departments in the university and M indicates the number of pairs of departments where the cables can be
laid. The following M lines will specify the distances between M pairs of departments as
dept1 dept2 distance
Where dept1 and dept2 are names of the departments (maximum 20 characters) and distance is a positive
integer (>0). Assume that the given distances between each pairs of departments will be unique and these M
lines will contain atleast one pair for each department.
Output specifications
The first line of the output will be names of the departments as they are included in the solution separated by
blank space. If two or more departments are included at a time then their names should be printed in the
alphabetic order. The next line will be the minimum length of cable required to form the intranet, terminated
with a new line character.
Sample Input/Output
input
7 10
physics chemistry 8
biology physics 9
biology office 15
chemistry office 4
chemistry sanskrit 5
sanskrit office 7
english office 16
english sanskrit 19
english cs 12
sanskrit cs 6
output
chemistry office sanskrit cs physics biology english
44
Hint : a simple prim's algorithm is implemented.| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Developer Program Engineer - 0of 0 votes
Answerslunatic server solution is monitoring the wrong file entry in the server.
- PriyaDarad June 06, 2012 in United States
so company made another a problem for it to monitor AVL tree violation.
The problem should be solved in java...
problem states that...
This problem requires you to monitor a tree for violation of the AVL balance criteria as the tree is being
constructed.
The input to the program consists of a sequence of numbers. As you read in each number, check where the
node is going to be inserted into the current tree. [At the start, the tree is empty.] If that insertion can cause
the balance of any of the nodes in the tree to go beyond what is allowed by the AVL criteria, DO NOT add
the number into the tree. Instead, print out the number into the standard output. Numbers which retain the
AVL property of the tree should be added to the tree at the appropriate place as per the method discussed in
class. Continue with the remaining numbers. Please note that you do not have to do any balancing of the
tree! The input is terminated by –1.
The output from the program consists of the numbers rejected by the program. At the end, you should also
print out the count of such numbers rejected.
Hint: It would help to keep the height of the left and right subtrees of each node along with the node. Also
note that the process of checking for violation and actually inserting are quite similar; in the former case you
do not update anything but do everything else. This observation can be used to write the code.
Sample Input/Output
Input
3 5 1 6 2 4 9 7 -1
Output
7 1
(This means rejected key(s) are: key 7, totally 1 rejected key)| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Developer Program Engineer Trees and Graphs - 0of 0 votes
Answerson last interview lunatic server solution asked 3 questions. one of them was very easy. the problem states that...
- PriyaDarad June 06, 2012 in United States
Given a stream of text, your task is to create a formatted paragraph out of it. The paragraph should be left justified and each line of text in the formatted paragraph should not exceed a given length. Each line should contain maximum possible characters.
In addition to the input text, a set of words with their possible hyphen positions will also be given. The hyphenation makes it possible sometimes to add incomplete words at the end of line, if the completed words overflow the line length limit. To indicate that this particular word is incomplete, a hyphen (-) is added at the end of such broken words. Remaining part of this word is placed at the beginning of the next line. The specified line length limit must be observed including the trailing hyphen character if any.
The input text will contain alphabets, digits, punctuation marks and spaces. The only white space character used is a blank space, which is used to separate words. Each line in a formatted paragraph begins with a non-blank character. Even if the input text has words separated by many spaces, your output should separate them by only single space or a line break.
Notes:
The list of hyphenated words will not include any punctuation marks that may occur in the text to be formatted. You may assume that the punctuation marks will occur only at the end of each word (alpha-numeric characters). That is there will not be words like They'll or Sita's anywhere in the input.
The word length will never exceed the line length limit.
The input text can always be formatted using the given constraints.
No word, hyphenated or otherwise will exceed a length of 20 characters.
Input specification:
First line has an integer n denoting the number of hyphenated words.
Next n lines give each of the hyphenated word with possible hyphen break positions in the word by a hyphen itself. For example, "hyphenate" is given as "hy-phen-ate" and "formatting" is given as "for-mat-ting".
Next line will be an integer denoting the maximum number of characters per line in the formatted paragraph, i.e., the line length limit.
Last line contains the text to be formatted into a paragraph. The entire text will be terminated by a new line. The length of text will not exceed 256 characters.
Output specification:
The output should be a sequence of characters, which begin each line of the formatted paragraph followed by a single new line character. Thus, there will be those many non-white space characters as there are lines in the formatted paragraph.
Sample Input and Output:
Input:
4
con-cept
pro-gram-ming
ob-vi-ous
im-pos-si-ble
25
Most people find the concept of programming obvious, but the doing impossible.
Output:
Mcos
Note : Candidate can not get characters of indices, which are multiple of 24.
you have to make program in java with proper coding and follow the problem statement.| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Developer Program Engineer Java - 0of 0 votes
AnswersLunatic server solutions asked this problem for fresher recruitment in india.
- PriyaDarad May 31, 2012 in United States
On monday we asked this problem for freshers.
there was a very easy problem.
problem states that...
You are required to write a program to do simple pattern matching, in a string. The string in which the pattern is to be found, henceforth referred to as Master String, can be composed of the following character sets:
a-z {any character in the range a to z}
A-Z {any character in the range A to Z}
0-9 {any digit in the range 0 to 9}
The pattern to be matched is also a string, henceforth referred to as Scan String. The Scan String can be composed of the above character sets, as well as two special characters, which are: '.' and '*'. The dot ('.') is to be interpreted as matching any one character from the above character sets and the star ('*') is interpreted as matching zero or more of the previously matched character. The Scan String may or may not contain the special characters.
A pattern is considered matched when the longest substring that satisfies the pattern is returned.
Input Specification
The first line of input contains the Master String.
The second line of input contains the Scan String.
Both Master String and Scan String will not be greater than 80 characters in length.
Output Specification
Your program must output the length of the longest substring matched. If there is no match, then the length of the matched substring is zero.
Input:
abcd23Abdaaaa4g9
.*Abd. { dot-star-A-b-d-dot }
Output:
10
Input:
aaadaaabbbb129cd
a.*d { a-dot-star-d }
Output:
16
Input:
0AbC1dEf2GhI3jKl4MnO5pQr6StU7vWx8Yz9
3JkL4 { 3-J-k-L-4 }
Output:
0
Input:
090m90mm90mmm90mm90m909
0m*9
Output:
5| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Developer Program Engineer Java - 0of 0 votes
AnswersIn this problem, you have to implement a variation of Insertion Sort as described below.
- dev May 27, 2012 in United States
Suppose X is an array of N positive integers to be sorted. In this scheme, another array Y is used to store the
sorted integers. This array is to be viewed as a circular array, ie. index (N-1)+1 = index 0 and index 0-1 =
index N-1. The sorted integers get stored in a circular manner in Y, ie, it is possible that the index of the
smallest integer may be greater than the index of the largest integer.
Eg. 6 8 _ _ _ 1 2 4 5 is a view of the array Y sometime into the algorithm. ’_’ indicates unused locations of
the array. Smallest integer 1 is at index 5, largest integer 8 is at index 1. So the sorted array in Y is to be
generated by printing the contents from index 5 to 1, assuming the array wraps around at the end, ie. after
index 8, the next index is 0.
Assume that h holds the index of the smallest integer in Y and t holds the index of the largest integer in Y.
Initially,
1. h = t = 0
2. Y[0] = X[0] ie. the first integer in X[] is copied as the first integer in Y[].
3. All other elements in Y[] are initialised to a dummy value -1.
The rest of the integers in X[] are now inserted one by one into Y[] such that Y[] always contains a sorted
list of integers, with the smallest integer at index h and the largest at index t. This is done in the following
manner:
Let I be the next integer from X[] to be inserted into Y[]. Scan the array Y downwards from index h (with
wrap-around at the end) till index t and find out the place in Y[] where I has to fit in. If I fits in at either end
of the list, then insert it at the appropriate place in Y[]. Modify either t or h as appropriate to indicate the new
array structure; ie. either t is incremented or h is decremented (with wrap-around).
If I fits in somewhere in the middle of the list, then I should be inserted by shifting all the S smaller integers
one place to the left or by shifting all the L larger integers one place to the right, depending on the number of
integers to be shifted. That is, if S < L, the smaller integers should be shifted one place to the left and if S >=
L, the larger integers should be shifted one place to the right. Again either h or t should be modified
appropriately.
Example
Integers to be sorted X[]: 25 57 37 48 12 92 86 33
Contents of Y[] after inserting each integer from X[]:
Initially (t=0, h=0)
25 –1 –1 –1 –1 –1 –1 –1
57 fits in at end (t=1)
25 57 –1 –1 –1 –1 –1 –1
37 fits in middle, S=1, L=1, so shift 57 right. (t=2)
25 37 57 –1 –1 –1 –1 –1
48 fist in middle, S=2, L=1, So shift 57 right. (t=3)
25 37 48 57 –1 –1 –1 –1
12 fits in at beginning, circular property, (h=8, t=3)
25 37 48 57 –1 –1 –1 12
92 fits in at end (t=4).
25 37 48 57 92 –1 –1 12
86 fits in middle, S=5, L=1, so shift 92 right, (t=5).
25 37 48 57 86 92 –1 12
33 fits in middle, S=2, L=5, so shift 12, 25 left (h=7, t=5).
33 37 48 57 86 92 12 25
Input Specification
The input will consist of a single line containing an integer N followed by the N integers to be sorted. All
integers are positive and are separated by a single space. There will be no duplicates among the N integers.
Output Specification
The output should consist of N lines, each line containing N integers. The N integers are the contents of Y[]
(ie. Y[0] to Y[N-1]) after the insertion of each integer from X[]. All integers on a line should be separated by
a single space. N will be less than 50.
Sample Input/Output
Input
8 25 57 37 48 12 92 86 33
Output
25 -1 -1 -1 -1 -1 -1 -1
25 57 -1 -1 -1 -1 -1 -1
25 37 57 -1 -1 -1 -1 -1
25 37 48 57 -1 -1 -1 -1
25 37 48 57 -1 -1 -1 12
25 37 48 57 92 -1 -1 12
25 37 48 57 86 92 -1 12
33 37 48 57 86 92 12 25| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Java Developer Data Structures Sorting - 0of 0 votes
AnswersRain strikes and the roads are flooded, Mr X has to get home from work. Your task is to make sure he
- dev May 27, 2012 in United States
returns home in the shortest time.
Consider the roads as a graph with crossings as nodes, and the path between two nodes as an edge. Assume
the graph is undirected and the nodes are numbered, 1 to V (V <= 50).
The input consists of :
1. An integer H on a line, this is the height of Mr X.
2. Two integers N and M on the next line, where, N is the number of edges in the graph. M is the
number of nodes in the graph.
3. A sequence of N lines each having 4 integers : C1 C2 T D where, C1, C2 are the nodes (or
crossings), T is the time it takes to go from C1 to C2. D is the water depth along the edge(or road)
from C1 to C2.
Note: The depth D has to be less than the height of Mr X for him to be able to take the road.
4. Two integers S and E indicating the node at which Mr X starts and where he is expected to go to,
respectively.
As output you have to give the shortest path starting at S, listing each vertex in the order and ending with E
that Mr X can take. Assume that there will be at least one way to reach the destination and that the shortest
path is unique.
Sample Input/Output
Input
5
10 7
1 2 10 4
1 4 6 3
1 5 8 2
2 3 2 1
3 7 1 2
2 6 1 3
4 6 4 4
6 7 2 5
5 4 2 6
5 7 6 1
1 7
Output
1 2 3 7| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Java Developer Data Structures - 0of 0 votes
AnswerConsider a hash table of size N, numbered 0 to N-1. You have to insert integers into this table using the
- dev May 27, 2012 in United States
hashing technique given below:
Let i be the integer to be inserted. Compute the index j of the location where the insertion is to be made as j
= i mod N. If this location is empty then put the element at this position else recompute the next location as
follows:
Remove the right most digit of i. Using the new value of i, recompute j = i mod N.
If the digit removed was odd, then move j locations forward from the current location else move j locations
backward from the current location (assume 0 as even). Note that this move will wrap around both the edges
of the table.
Keep doing this till you either find a free location or all the digits of i have been removed. When i comes to
only one digit, and its rightmost digit is removed, the number remaining is zero - therefore, this will lead to a
zero-step move.
If all digits of i have been removed and yet unable to find a free location, from the last location tried, start
moving in the direction corresponding to the last digit removed. Keep moving till you detect a free location.
Assume that the number of integers inserted is not more than the table size.
Input Specification
The first line will contain just one integer. This will give the table size, N. On the next line will be the list of
positive integers that need to be inserted into the table. The integers will be separated by a space each, and
the last integer will be -1 indicating end of input. (-1 is not to be inserted into the table).
Output Specification
The output should contain, for each integer, the locations that were checked while inserting that integer
(including the location in which the integer was finally inserted). The locations checked for each of the
integers should be output on a line by itself, separated by one space each, each line being terminated by a
new line.
Sample Input/Output
Input
7
38 52 145 16 179 4 -1
Output
3
3 5
5 5 4
2
4 0
4 4 3 2 1| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Java Developer Hash Table - 0of 0 votes
AnswersOn last sunday in the interview round this question was asked.
- PriyaDarad May 27, 2012 in United States
An older person has a very old computer at his house. It is so old that there is no notion of virtual memory in the operating system. Instead it uses a simple memory allocation technique called the 'Best Fit Algorithm'. The BFA works like this:
Whenever a request comes in for some memory space, the OS looks for the smallest, continuous empty space, which can satisfy it, and allocates a portion of this region to the program making the request. If such space cannot be found, the program is terminated and all the memory used by the program is freed. Any program can get terminated due to two reasons:
The program exits
Enough memory is not available to start the program or keep it running
All memory requests that come in at the same time-instant are processed in ascending order of process-id. If while processing, a program is terminated for lack of memory, all memory held by it is freed before processing any other request and no further memory requests by the terminated program are considered. All termination is also done in order of process-id.
You have to write a program to simulate this algorithm and print out the number of processes that were terminated due to lack of memory.
Note:
1.No process will request for memory before its start-time or after its end-time.
2.All memory sizes are specified in KB.
3.The memory is linear in nature, i.e., addresses do not wrap around. It starts at zero and goes up to N-1 KB.
4.At a given time unit, all processes that have reached end-time will be terminated (and memory freed) before other memory requests are serviced.
5.The total free space available in memory might be enough to satisfy a request, however the OS will terminate the process if a continuous region of empty space is not found
Input specification:
First line has an integer N (0 < N <= 1000), size of the memory in KB.
Second line of input will have integer P (0 <= P <= 20), the total number of processes to be run on the system.
Next P lines will have data for each process in the following format:
<process-id> <start-time> <end-time> <initial-memory>
These input lines will be sorted in ascending order of the process-id.Process-id will be unique integers greater than zero.
Next line will have integer R (0<= R <= 20), which specifies the subsequent memory requests by any process.
Next R lines have the following format:
<process-id> <request-time> <memory-required>
Output specification:
An integer specifying the number of processes that were terminated due to lack of memory
Sample Input and Output:
Input:
100
4
1 3 7 20
2 0 4 30
3 0 3 70
4 0 10 25
2
3 2 30
2 2 10
Output:
2
Input:
10
2
1 0 8 4
2 0 3 2
3
1 1 2
2 1 2
1 4 4
Output:
1| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Developer Program Engineer - 0of 0 votes
AnswersAn older has a very old computer at his house. It is so old that there is no notion of virtual memory in the operating system. Instead it uses a simple memory allocation technique called the 'Best Fit Algorithm'. The BFA works like this:
- PriyaDarad May 26, 2012 in United States
Whenever a request comes in for some memory space, the OS looks for the smallest, continuous empty space, which can satisfy it, and allocates a portion of this region to the program making the request. If such space cannot be found, the program is terminated and all the memory used by the program is freed. Any program can get terminated due to two reasons:
The program exits
Enough memory is not available to start the program or keep it running
All memory requests that come in at the same time-instant are processed in ascending order of process-id. If while processing, a program is terminated for lack of memory, all memory held by it is freed before processing any other request and no further memory requests by the terminated program are considered. All termination is also done in order of process-id.
You have to write a program to simulate this algorithm and print out the number of processes that were terminated due to lack of memory.
Note:
1.No process will request for memory before its start-time or after its end-time.
2.All memory sizes are specified in KB.
3.The memory is linear in nature, i.e., addresses do not wrap around. It starts at zero and goes up to N-1 KB.
4.At a given time unit, all processes that have reached end-time will be terminated (and memory freed) before other memory requests are serviced.
5.The total free space available in memory might be enough to satisfy a request, however the OS will terminate the process if a continuous region of empty space is not found
Input specification:
First line has an integer N (0 < N <= 1000), size of the memory in KB.
Second line of input will have integer P (0 <= P <= 20), the total number of processes to be run on the system.
Next P lines will have data for each process in the following format:
<process-id> <start-time> <end-time> <initial-memory>
These input lines will be sorted in ascending order of the process-id.Process-id will be unique integers greater than zero.
Next line will have integer R (0<= R <= 20), which specifies the subsequent memory requests by any process.
Next R lines have the following format:
<process-id> <request-time> <memory-required>
Output specification:
An integer specifying the number of processes that were terminated due to lack of memory
Sample Input and Output:
Input:
100
4
1 3 7 20
2 0 4 30
3 0 3 70
4 0 10 25
2
3 2 30
2 2 10
Output:
2
Input:
10
2
1 0 8 4
2 0 3 2
3
1 1 2
2 1 2
1 4 4
Output:
1| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Computer Scientist Java - 0of 0 votes
Answersin this round the question was
- PriyaDarad May 25, 2012 in United States
java solution will be preferred.
programmar will get benefits.
Finding data on a huge hard disk has been a difficult task for computer manufacturers. In the constant quest to speed up the seek-time to find data, they've come up with a new algorithm. A simplistic view of a hard disk is as follows:
A hard disk consists of several platters, each of which has a head for reading and writing data. Each platter is divided into 80 tracks, numbered 1 to 80. Initially all the heads are on track 1. Once a head reaches a track, it can read all the data requests that have come in so far for that track, in one read-operation, which takes one unit of time. A head takes one unit time to move from one track to the neighbouring track. To minimize the seek-time, after every read operation, the head will move in the direction of the nearest pending request. That is, if the head was moving toward track 80 and while it was on track 5, two requests came, one each for track 2 and track 18. The head would continue to move in the same direction, read the data on track 18, re-evaluate the nearest track to be 2 and start moving toward track 2. If two competing requests for different tracks are equidistant from the head, then it will move in the direction of track 1. Initially the head of all platters is at rest. The head does not move if there are no requests for any track at the particular time.
The head on each platter follows this sequence during each time unit: -
1.All the requests for the current time unit are noted.
2.If there are any requests for the current track, read occurs in the same time unit.
3.If there were no reads, the head moves, if necessary.
4.Decides the direction of movement, if necessary.
You have to write a program to calculate the number of fulfilled requests per platter, after the specified time. If a particular platter has had no read-requests throughout the simulation, its count of fulfilled requests is '0'. The simulation starts at the beginning of time unit 1 and finishes at the end of time unit T
Input specification:
The first line of input will be an integer P (0
<= 20), signifying the number of platters.
The second line of input will be an integer T, specifying the time unit after which the output is to be printed.
The third line of input will be an integer N (0<=N<= 100), specifying the number of read requests that are coming in.
The next N lines will contain the read requests in the following format:
<time-of-request><space><platter-number><space><track-number>
Platter numbers start from 1 to P
All of the above will be integers separated by a single space.
Output specification:
Your program has to print N lines of output in ascending order of platter number in the following format:
<platter-number><hyphen><requests-fulfilled>
Sample Input and Output:
Input:
2
5
4
1 1 1
1 1 2
3 2 3
2 1 3
Output:
1-3
2-0
Input:
3
53
7
2 3 50
51 1 2
1 1 3
51 1 2
1 2 80
2 2 5
2 2 1
Output:
1-3
2-2
3-1| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Developer Program Engineer - 0of 0 votes
Answershi to all tech brains.
- dev May 25, 2012 in United States
we made an interview round and ask this problem.
problem needs complete solution in java.
Any one of you who can solve it may appreciate and will get some benefits.
In this problem, you have to implement a sorting algorithm called Tournament sort, which uses a complete
binary tree.
The depth D of the tree will be given as input. Also, N positive integers will be given, where N is the Dth
power of 2 (ie, 2 ** D).
Construct a complete binary tree of depth D and fill in the leaf nodes with the N given integers in the order
given ie. the first integer should be at the leftmost leaf and the last integer should be at the rightmost leaf.
Next, update all the non-leaf nodes in the tree such that each nonleaf node contains the maximum of the
values in its children. Thus, the root will contain the maximum of all the N integers.
Implement a procedure ’maxdelete’ which essentially removes the maximum value from the tree and updates
the tree as follows:
1. traverse the tree from the root
2. find the leaf with the maximum value ie. the value at the root. (note that in this tree, if the value at a
non-leaf node is T, either its left child or its right child will have value T).
3. replace the value at that leaf node with -1 and
4. update the rest of the non-leaf nodes such that each non-leaf node contains the maximum of the
values in its children.
Perform the ’maxdelete’ operation 3 times on the tree and print out the INORDER traversal of the tree after
each operation.
Example
Given depth = 2
Given integers: 25 57 37 48
Constructed and updated tree:
57
/ \
57 48
/ \ / \
25 57 37 48
after first 'maxdelete'
48
/ \
25 48
/ \ / \
25 -1 37 48
after second 'maxdelete'
37
/ \
25 37
/ \ / \
25 -1 37 -1
after third 'maxdelete'
25
/ \
25 -1
/ \ / \
25 -1 -1 -1
Input Specification
The input will consist of a positive integer D followed by a positive integer N (where N is the Dth power of
2) followed by N positive integers. All the integers are separated by a single space and will be on a single
line. There will be no duplicates among the N integers. D will be greater than 1 and less than 9.
Output Specification
The output should consist of 3 lines. Each line should contain the INORDER traversal of the tree after a
’maxdelete’ operation. All the integers on a line should be separated by a single space.
Sample Input/Output
Input
2 4 25 57 37 48
Output
25 25 -1 48 37 48 48
25 25 -1 37 37 37 -1
25 25 -1 25 -1 -1 -1| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Java Developer Data Structures - 0of 0 votes
AnswersConsider a service counter. People waiting for service form a queue. At the start, the queue is empty and
- Anonymous May 23, 2012 in United States
time is 0. The service time per person is 3 minutes.
The input to the program consists of an integer N followed by a sequence of integers indicating the arrival
time (in minutes) of the customers. These times are given as offset from the start of the simulation, so that an
input of 44 means 44 minutes from the start of simulation. The sequence of input numbers is terminated by
the number -1.
Your program must simulate the queue and print out the following:
1. The number of customers waiting in the queue at time = N minutes from the start of simulation.
2. The arrival times of the customers in the queue at that time, in increasing order.
Each integer must be separated by a space. Terminate your output with a newline character.
For doing the computation, you can assume that if the counter is expected to be vacant at time t, the first
person in the queue will be scheduled for service, before the counting is done for time t.
You must use the queue data structure to solve this problem.
Sample Input/Output
Input
9 0 2 5 6 6 8 10 -1
Output
2 6 8
provide the solution using QUEUE.
This problem will tell you your coding power.| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Developer Program Engineer Data Structures - 0of 0 votes
AnswersIn this problem you have to write a program to check if two given binary trees are structurally equivalent.
- PriyaDarad May 22, 2012 in United States
Two trees are structurally equivalent if they are both null or if the left and right children of one are
structurally equivalent to the RESPECTIVE children of the other. In other words, when you draw the trees
on paper, they should LOOK alike (ignoring the values at the nodes).
The input to the program is a number N followed by N lines of input. Each line consists of a sequence of
positive numbers terminated by -1. There will be no duplicate numbers in any of the lines.
Construct a binary search tree with the input in the second line and use this as the basis-tree. For each of the
remaining N-1 lines, construct a binary search tree and compare against the basis tree for equivalence. If the
trees are equivalent, print YES else print NO. Also print the depth difference between the two trees (ie, depth
of the bigger tree minus the depth of the smaller tree). Both these for a given tree pair must be on one line
separated by a space. The answers for the different pairs must be on separate lines.
Sample Input/Output
Input
5
1 3 2 4 -1
4 1 2 3 -1
3 2 1 4 -1
4 3 2 1 -1
1 3 4 2 -1
Output
NO 1
NO 0
NO 1
YES 0
(Note that the depth difference will be zero if the trees are equivalent.)| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Developer Program Engineer - 0of 0 votes
AnswersConsider a service counter. People waiting for service form a queue. At the start, the queue is empty and
- PriyaDarad May 22, 2012 in United States
time is 0. The service time per person is 3 minutes.
The input to the program consists of an integer N followed by a sequence of integers indicating the arrival
time (in minutes) of the customers. These times are given as offset from the start of the simulation, so that an
input of 44 means 44 minutes from the start of simulation. The sequence of input numbers is terminated by
the number -1.
Your program must simulate the queue and print out the following:
1. The number of customers waiting in the queue at time = N minutes from the start of simulation.
2. The arrival times of the customers in the queue at that time, in increasing order.
Each integer must be separated by a space. Terminate your output with a newline character.
For doing the computation, you can assume that if the counter is expected to be vacant at time t, the first
person in the queue will be scheduled for service, before the counting is done for time t.
You must use the queue data structure to solve this problem.
Sample Input/Output
Input
9 0 2 5 6 6 8 10 -1
Output
2 6 8| Report Duplicate | Flag | PURGE
Lunatic Server Solutions Developer Program Engineer Data Structures