The number of ways in which ten candidates A1,A2,A3......A10 can be ranked if A1 and A2 are next to each other is
2!.9!
Consider A1,A2 as one entity so that there are 10-2+1= 9 candidates which can be arranged amongst themselves in 9! ways.
But these two A1 and A2 can be arranged among themselves in 2! =2 ways.
Hence the number of ways A1 and A2 are together is 2!.9! ways.