MYQ1 - The Blind Passenger
The seats of an Ultra Deluxe Semi-sleeper bus in Thuvax country are numbered according to the following rules:
- Seat number 1 is reserved for the bus conductor.
- Remaining seats are numbered as shown in the figure below.
- The seating arrangement is as shown below.
RowNo Left Right W A A M W 01 1 02 03 04 05 06 2 11 10 09 08 07 3 12 13 14 15 16 4 21 20 19 18 17 5 22 ............
A blind person enters the bus with a reservation ticket mentioning his seat number. He meets you at the start of the passage and shows you his ticket. Based on the seat number, help him find his seat by telling him the row number (1,2,...), seat position(window or aisle or middle), and the direction(left or right).
First line contains a positive integer t (t <= 10^5) denoting the number of test cases.
Each of the next t lines contain a positive integer n (n <= 10^9) denoting the blind person's seat number.
Output one line for every test case in the following format:
- If the seat number is same as the conductor's seat, print "poor conductor"
- else, print <row_number> <seat_position> <direction>
- row_number: represents the row number from the entrance (a positive integer)
- seat_position: can be one of "W" or "A" or "M" for window, aisle and middle respectively.
- direction: can be either "L" or "R" for left or right respectively.
Input: 3 1 2 3 Output: poor conductor 1 W L 1 A L
Solved using Binary Search :D
AC in one go!!
simple if-else question.
TLE in java but AC in C
AC in one go...
Prakhar Dev Gupta:
AC in a go!
just observe the pattern and try to make a formula for general condition
Do take care of seat positions i.e Window, Aisle, Aisle, Middle, Window.Last edit: 2015-05-27 22:23:20
Take test cases and n as int. And according to comments, the problem is not designed well. Well, if you see with concentration then it is obvoius that 3,4 and 5 will be R because if 3 is L then how will the passenger distinguish between 2nd coloumn and 3rd coloumn(both will be A and L). In that case, it will be tough for passenger to reach the correct seat. He will either choose the 2nd coloumn or 3rd coloumn of which one is correct.Last edit: 2015-04-15 20:51:20
1st time AC in 1st attempt.. that feel.. :)