Several decades ago, George Harrison lost a copyright infringement lawsuit because his "My Sweet Lord" was very similar to Ronnie Mack's "He's So Fine." There have been many cases (and non-cases) before and since regarding similarities between songs, whether intentionally plagiarized or by accident.
In conventional Western music, there are 12 pitches ("notes") in however many octaves that can be played and, especially, heard. Counting double-sharps and double-flats, there are 35 note names, but they are the same 12 pitches (e.g., A double-sharp, B, and C-flat refer to the same pitch, in most cases). At the very basic level, a piece of music consists of a melody, a time signature implied by the melody (e.g., 4/4 meter), and a harmony (i.e., chord progression) also implied by the melody. With those elements in place, a piece of music can easily be transposed to a different key and/or changed in tempo -- and it would still be the same piece of music.
The conventional "wisdom" of having 12 notes is that accidental similarities are an inevitability. This is a misleading statement mathematically, but it is shorthand for a deeper societal truth*:
Let's get the math (as much as I can understand and explain) out of the way. Yes, there are only 12 notes in conventional Western music, with micro-tones used in passing (e.g., slides and vibrato) or by accident (e.g., bad performances). There are, if I'm thinking correctly, 48 possible triads, that is, major chords, minor chords, diminished chords, and augmented chords. There are possibly several hundred variations, additions, subtractions, inversions, and substitutions of these 48 triads (e.g., suspended 4th chords, root-5th power chords, dominant 7th chords, etc.). There is an exponential amount of variation when creating melodies, harmonies, chord progressions, and associated rhythms (e.g., whole notes, half notes, quarter notes, eighth notes, etc.), and time signatures (e.g., 3/4, 4/4, 6/8, 5/4, etc.).
With myriads-upon-myriads of possibilities, statistically speaking, accidental similarities should not be inevitability. However, cultural standards tend to definite which combinations are "good" and which combinations are "bad." Let's try to define the word good, at least for this topic. Artistic endeavors, from music to visuals to food, cannot be judged by an objective good, but rather a more subjective scale of accessibility. Music theory limits culturally pleasing melodies/harmonies to defined scales and modes, with room for related scales and modulations. Popular music tends to limit which combinations of melody and meter are accessible to audiences, mostly regardless of genre. Genre conventions tend to limit which arrangements of instrumentation are good for genre (the fuzzy overdrive of hard rock guitar vs. the heavy distortion of metal guitar, or hip hop's use of samples and programmed beats vs. country's fiddles and twangy vocals), but the accessibility of melody/harmony and rhythm tend to be the same across all genres of popular music.
The deeper societal/cultural/pop cultural truth is that a very small combination of pitches and beats (and words, usually) can be considered accessible to audiences. If melodies, harmonies, and time signatures could be generated purely randomly, with no algorithms to adhere to cultural conventions -- there's probably and app for that -- I can guess that less than 1% of these musical combinations might be hit songwriting, perhaps 10% might have potential for some audience appeal (with major adjustments), but the rest might be off-key, inaccessible musical gibberish. This app would generate a lot of original ideas, but the current culture would judge a lot of that as inaccessible and weird -- except for a very small audience, if any, who would be into experimental things.
*I've put an asterisk earlier for the TL;DR point of the blog post: Conventional Western music has only 12 notes, and because of cultural limitations, accidental similarities among songs are inevitable. Assuming there was no intentional plagiarism involved, that's why "Stay With Me" sounds so much like "I Won't Back Down." That's why the bulk of recent (the past several decades) of pop music -- from dance pop to rock to R&B to country -- boils down to a soup of sameness. That's why popular recording artists tend to repeat themselves, their audiences love them for that, and there's a lot of money to be made.
In popular music, as with all artistic endeavors in popular culture, good really means accessible, and original is mostly impossible with contemporary audiences. Original is for the future and alternate realities. Original is for artists with no current audience, with a very real possibility of no future audience, ever.
My good advice: Be original.