Lunatic Server Solutions Interview Question Developer Program Engineers
- 0of 0 votes
in this round the question was
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
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:
Platter numbers start from 1 to P
All of the above will be integers separated by a single space.
Your program has to print N lines of output in ascending order of platter number in the following format:
Sample Input and Output:
1 1 1
1 1 2
3 2 3
2 1 3
2 3 50
51 1 2
1 1 3
51 1 2
1 2 80
2 2 5
2 2 1
Country: United States