Gates would have had access to Dartmouth BASIC, which he likely referenced and possibly plagiarized while writing Altair BASIC. Back in that day, people shared software freely, so Gates took advantage.

https://en.wikipedia.org/wiki/Dartmouth_BASIC