How many kings or how many generations?
I think Matthew was basically counting "periods of time" not how many kings. Kings' names were being used to represent or name some generations or some periods of time. (but not in every case).
First of all, The word Generation can also mean an age (i.e. the time ordinarily occupied be each successive generation), a space of 30 - 33 years https://www.blueletterbible.org/lang/lexicon/lexicon.cfm?Strongs=G1074&t=KJV
Look at the next verses to understand how Matthew was thinking in the number of generations or ages and how and when it begins and ends for him.
So all the generations from Abraham to David are fourteen generations;
and from David until the carrying away into Babylon are fourteen
generations; and from the carrying away into Babylon unto Christ are
fourteen generations... (Matthew 1:17 KJV).
The first generations as we see are from Abraham to David , they are 14 generations or periods of time and they were represented by 14 kings.
For the second group of generations, if we look closely to how Matthew determined its beginning and end, we will see Matthew says it begins with David time and ends with not a king's name but with another period of time, a moment, an event which is the Babylon Captivity or as the KJP puts it "the carrying away into Babylon.
It is clear then that Matthew meant by generation periods of time and was counting depending on that.
So the generation here is from David to carrying away into Babylon. And they are 14 generations (periods of time).
In this period Jechonias and his brothers were born. (Matthew 1:11 KJV)
The third and last group of generations Matthew speaks about also begins not with a king but with another period of time. Matthew describe this period as "from the carrying away into Babylon ".
From carrying away into Babylon unto Christ was another group of generations which are 14 generations (periods of time).
That period (from carrying away into Babylon) carried another dramatic and different experience to the people than the period of Captivity in the second group.
In this period Jechonias and his brothers were brought to Babylon. (Matthew 1:12 KJV)
If we want to count kings (as represent generations) like many do, we have to count Jechonias two times as he represented two different periods and generations.
He represented the period of the begining of the occupation of his country as he was born in that time and he also represented the time of carrying away to Bablyon as he was brought to Bablyon in that time.
Generally speaking, Matthew used GENERATIONS as PERIODS OF TIME in his mind when he was meditating in Jesus' time of birth and relating that to Israel history as it is so clear in (Matthew 1:17 KJV).