The following dihaloalkanes gives an N-(haloalkyl)phthalimide on reaction with one equivalent of the potassium salt of phthalimide. Deduce the structure of the phthalimide derivative formed:
If you look at the potassium salt of phthalimide, the nitrogen part, with its negative charge, is a capable nucleophile. This charge is stabilized by the presence of the two electron-withdrawing carbonyl groups on either side of the nitrogen anion. But it is a nucleophile nevertheless:
As shown above, the nucleophile attacks the carbon bearing the better leaving group. In general, Bromine is a much better leaving group than Fluorine in nucleophilic substitutions. The Bromide might form KBr depending on the nature of the solvent.