Suppose that I as a UK citizen living in the UK am given money by an American who then dies. Do I have to pay inheritance tax to either the UK or US governments?
To extend on @ohwilleke's answer about US inheritance tax, I can answer the UK side of things.
UK inheritance tax does not apply to inheritances from abroad, unless that person was domiciled in the UK or some of their assets were in the UK.
If you are not a UK resident for tax purposes (which, from the context of your question is unlikely), then you wouldn't even have to pay tax on the interest you earned from depositing the inheritance.
If the deceased were taxed for being domiciled in the UK, and the US taxed your inheritance, you'd actually qualify for tax relief from HMRC based on what you'd already paid the IRS.
If you are not domiciled in the UK for tax purposes, and neither was the decedent you would owe precisely zero to HMRC in the UK.
More info can be found here: https://www.taxoo.co.uk/uk-resident-receiving-inheritance-from-abroad/
I can only answer half of the question.
The U.S. has an estate tax that applies to U.S. citizens and U.S. residents who die on the property that they own at their death. So, if a U.S. citizen leaves an inheritance to a U.K. citizen, any death taxes are paid by the U.S. citizen's estate (and very few people pay it because the cutoff exceeds $12 million of taxable gifts made by the decedent during life plus the fair market value of the decedent's assets at death).
Since this involves a gift made before death, the U.S. gift tax applies, rather than the U.S. estate tax, but the U.S. gift tax is imposed on donors, not recipients, and also has an annual exemption of $17,000 per person per year ($34,000 per person per year from a married couple).
I do not know how the U.K. would tax receipt of a gift before death from a U.S. person.
I suspect that, since this is a lifetime gift rather than an inheritance, that the only tax that would apply is a tax on gifts, not a tax on inheritances, since a lifetime gift isn't an inheritance.
I think you have misunderstood the requirements to pay inheritance tax, as it is...
...a tax on the estate (the property, money and possessions) of someone who’s died.
You, apparently, have not died. Instead, you are the beneficiary of a "cash gift from overseas" and as such...
You won't have to pay Income Tax on cash gifts.
But... any profit it generates (e.g. from investing it, or interest gained from a bank account) may be taxable depending on your particular circumstances.