Write the mechanism of the following reaction:

The given reaction is SN2 reaction. The nucleophile, Nu– approaches the carbon atom on the side opposite from the halogen and forms new covalent bond with the carbon. This is because KCN is an ionic compound, K+ [C ≡ N]–. Since carbon carrying a lone pair of electrons is more reactive than nitrogen carrying a lone pair, the transition state is formed by the carbon of the cyanide ion forming band with the carbon halogen bond thus,