The ending of a mystery novel is often unexpected, yet it makes perfect sense.