Charlie Puth recalled the writing of the song to Billboard
"We were all at Conway, which is a really nice recording studio. And we were all just messing around; nothing was really coming when we were writing."
"I just pictured what a leprechaun would sing, because I think there were Lucky Charms in the room or I had had them for breakfast," he continued. "Like, what would a leprechaun melody be? [Sings 'Bedroom Floor' hook.] And Noel, who works with Ryan Tedder and OneRepublic, had this cool sound like 'boom boom boom' and I was thinking, 'Oh, it could be like a dance record or something like that.' And out of nowhere, that melody, that joke melody I had, fit perfectly on to one of the dancey chords."
Puth concluded: "The song originally started [with] two parts and we flipped the two parts and 'then it was over,' and we were like, 'Oh it's so great! Your clothes are talking!' We were dancing around, such a fun songwriting session."