It can last anywhere from a few hours to 60 hours after the last hit. It can even be detected up to seven to eight months after the last usage. There is no way to avoid detection at all.
Within 3 to 5 days, Cocaine should be out of your friend's system. Also, if you're worried about detection, keep in mind that coke is water soluable, so drink plenty of water for it to go away.