Good answers below, KEY IS THAT EVERYTHING IN NEGOTIABLE. The standard FAR/BAR contracts for sale and purchase spell out responsibility, but they are amendable. So, read everything you are aksed to sign.
Weichert, Realtors - Hallmark Properties
If this is a short sale do not be surprised if the lender asks you to help pay the HOA fees. It happens. My suggestion if they ask is to agree to pay a small portion...that way they are unable to say that you did not help.
If you are purchasing a home via a tax sale or auction, I would recommend that you consult an attorney or title agent. Typically the buyer is responsible for any unpaid liens, taxes, etc. On a normal sale, I agree with Bill's comments below.
Typically the seller is responsibe for paying all back taxes and will receive a credit for the remaining HOA fees paid in advance. However, everything is negotiable and should be addressed in the purchase contract.