Can anyone please comment on my doubt here. (@Satbir @dd)
I completely agree with @chauhansunil20th and I think the answer is 8.
The sequence is: 181,178,188,170,201,138,265,10,521 --> This will give 8 times change in direction of the head. If we include the first direction as well, then we will get answer as 9.
Here's how I got the sequence.
To get the sequence we should cumulatively add the below numbers with initial number as 180. Here is the sequence.
+1 -3 +7 -15 +31 -63 +127 -255 +511 -1023 +2047
This will give us: 181, 178, 185, 170, 201, 138, 265, 10, 521, -502, 1545.
Please note that the cylinder number -502 is negative. Assuming cylinder numbering starts from 0, this negative cylinder number is not valid and hence can't be considered. If we ignore this negative cylinder number, we will get 8 times change in direction of the head.
We can even try cumulatively adding the below sequence to initial cylinder number 180 as well.
-1 +3 -7 +15 -31 +63 -127 +255 -511 +1023 -2047
This will give us: 179, 182, 175, 190, 159, 222, 95, 350, -161, 862, -1185
Please note here also the 2 cylinder numbers -161 and -1185 are negative. If we ignore these negative cylinder numbers we will get only 7 times change in direction of the head.
Hence maximum number of times cylinder head changes its direction is 8.