In peripherals, priority is given based on the speed of the device. Higher the speed, higher the priority. Hard disk has the highest speed(MBps) among the given options and thus has the highest priority. Whereas, keyboard is the slowest one because we humans write so slow(like 1-3 word per second) when compared to CPU, and thus keyboard has lowest priority. You may have noticed sometimes that when you are copying/moving a large file on to your hard disk from other device, like pen drive, and then you try to type something using keyboard the typed words are shown with some lag. This is because of the priority being given to hard disk right now.

why transfer rate matters here? Priority is based on how critical a device is. In many real time systems, keyboard should have the top priority but on a computer system, I guess this is a bit ambiguous.

@arjun sir : By transfer rate . it can be like if its give high tarnsfer rate then old data would be getting repleced by next data very soon so now to avoid data loss , hardisk has a higher priority ? is it ryt ?

Speed differences between two devices. A slow device may write data into a buffer, and when the buffer is full, the entire buffer is sent to the fast device all at once. So that the slow device still has somewhere to write while this is going on, a second buffer is used, and the two buffers alternate as each becomes full.

When I read problem, I felt it should be keyboard, as initially BIOS is loading and it has to respond to any commands from keyboard. Till that disk is not yet accessed. And any command fed from keyboard has to be abided over anything from disk (as I already said disk is not loaded, so in fact nothing will come from disk). So as a pure command input, keyboard should be given higher priority.

why transfer rate matters here? Priority is based on how critical a device is. In many real-time systems, a keyboard should have the top priority but on a computer system, I guess this is a bit ambiguous.

The speed of I/O devices matters here because if we talk about keyboard then one can maximum type 3-4 characters in 1 sec. and within 1 sec, our CPU can execute millions of instructions(MIPS) depends on a frequency of the processor, main memory, and cache data transfer rate is faster than a keyboard, printer, scanner etc..

If CPU will service interrupt of the keyboard then there will be a chance that MM which has high data generating speed within some buffer, we might lose some data that is the reason CPU has to first service interrupt of higher speed device than compare to slower ones. That is how interrupt driven priority based I/O implemented.