Solution:
Number of ways of arranging beds
Number of ways in which Madhu and Puja have theire beds together is
Thus, required number of ways
Suppose that six students, including Madhu and Puja, are having six beds arranged in a row. Further, suppose that Madhu does not want a bed adjacent to Puja. Then the number of ways, the beds can be allotted to students is
Number of ways of arranging beds
Number of ways in which Madhu and Puja have theire beds together is
Thus, required number of ways