First tell spraying apart from missing the litter box — these are different problems with different solutions.
Spraying: the cat stands, tail up and quivering, and directs a small amount of urine backwards onto a vertical surface — a wall, a table leg, the corner of the sofa, a bag.
Missing: the cat squats on a horizontal surface and empties the bladder fully. The puddle is a normal volume.
If it is missing the box
Rule out health first. Sudden puddles outside the box — especially if the cat squats repeatedly, strains, over-grooms, or cries while urinating — are a reason to see a vet, not to look for a character flaw. Especially in male cats: a urinary blockage develops within hours and is fatal.
If health is fine, the box itself is usually the problem. The rule is simple: one more box than you have cats. They should stand somewhere quiet but not in a dead end with no second way out. Use the litter the cat is used to; a change of brand is often the entire cause. The box should be big enough for the whole cat and clean enough.
If it is spraying
Spraying is not dirtiness and not revenge. It is a message: I am here, this is my territory. Cats spray when they feel that territory is under threat.
Common triggers: an unneutered male in season; a new animal in the house; a cat outside the window or the door; moving house, renovation, new furniture, guests; unfamiliar smells on shoes and bags; a change in the household routine.
What to do
Neutering resolves it in most males, provided it is done before the behaviour hardens into habit. Discuss timing with your vet.
Clean sprayed spots with an enzymatic cleaner, not bleach and not vinegar. Bleach smells to a cat much like a marker and invites a repeat. Ordinary cleaners remove the smell for your nose, not for the cat's.
Block the view of outdoor cats: film on the lower part of the window, curtains, furniture moved away from the sill. Add vertical space — shelves, cat trees, tall scratching posts. A cat with a high vantage point feels more secure.
What not to do
Do not rub the cat's nose in it, shout, or hit. A cat does not connect punishment with something it did half an hour ago, but it connects it very well with you. The result is anxiety, and anxiety is the main cause of spraying in the first place. After punishment the problem almost always gets worse.