anjali306
BAN USER- 0of 0 votes
AnswersThere is a door to enter a restroom. Once you enter the restroom there are N toilets starting from 1, 2,... to N. The toilet which is near to entry door starts from 1 and then it serially goes till N. You can use toilet based on below conditions:
- anjali306 in United States
1. If none of the toilets are occupied then choose one which is nearest to the entry door(which is toilet#1).
2. If at least one toilet is occupied then choose that unoccupied toilet which is farthest from the occupied ones.
3. If there are more than one unoccupied toilets whose farthest distance from the occupied ones are same then choose one which is near to the door.
For example:
Let's say there are 5 toilets.
-> First person comes and occupies toilet#1(Based on rule#1).
-> 2nd person comes and occupies toilet#5(Based on rule#2).
-> 3rd person comes and occupies toilet#3(Based on rule#2). Note that the farthest distance would have been formed when the new person would have occupied toilet#2(or toilet#4) but with that, the distance between toilet#2(unoccupied) and toilet#1(occupied) would be just 1.
-> 4th person comes in. Now from toilet#1 to toilet#5, only toilet#2 & toilet#4 are unoccupied. Now there are 2 toilets(#2 & #4) whose farthest distance from unoccupied ones are equal(=1). So rule#3 will apply and toilet#2 will be occupied.
You have to find the sum of those toilet numbers which are occupied.
So in above example after 4th person, toilet numbers which are occupied are #1, #5, #3 & #2.
So answer would be 1+5+3+2 = 11.| Report Duplicate | Flag | PURGE
Amazon
RepNancy Nash, Area Sales Manager at Absolute Softech Ltd
Prior to my current job I was training soap scum in Africa. Earned praised for my work developing wooden trains ...
Repinfo@kukooo.in, Reverse Engineering and System Developer at Abs india pvt. ltd.
Enthusiastic about implementing wazifa to make someone love you.Prior to my current job I was short selling action figures ...
RepHave some experience building shaving cream in Mexico. Prior to my current job I was marketing inflatable dolls in Jacksonville ...
RepRosendoVBarhorst, Employee at US
Enthusiastic about implementing wazifa to make someone love you.Prior to my current job I was short selling action figures ...
RepHave a strong interest in donating yogurt for the underprivileged. Spent several years building cabbage in Miami, FL. Spent several ...