Yup. I also remember Jay Rock saying he walked in the studio when Kendrick was working on the Black Panther soundtrack. Kendrick basically said hey man come get on this shyt, pulled up King's Dead, and had Jay Rock record that verse. But if you listen to the reference track, you can hear that after the first verse there are parts that Jay Rock wrote for himself. I can't really compare that to say...Kanye/Dre/etc having entire songs written for them. Kendrick gave him a verse/melody, and Jay Rock also came up with another verse.
I wouldn't compare that to ghostwriting. When I think of ghostwriting I think of like....Kendrick writing for Doja Cat lol. It'll come out eventually but he wrote Paint The Town Red and some other shyt for her. Listen to that shyt and it'll become obvious too lol.