As noted, the problem is that the Merina monarchy unified the island much too late. They'd need to start centuries earlier, but centuries earlier the coastal kingdoms like the Sakalava were more powerful, wealthier, and better able to gain access to foreign weapons. A highland state unifying Madagascar is probably a fluke of history, since the lowlands are much more malarial and caused a sizable death rate to Merina administrators and soldiers.
As for population, it should be noted that because of subjugation of recently conquered lands, something like 1/3 of the island's population died during the early 19th century. Epidemic and famine killed many as well. Such traumatic unification would need to have been pushed back for the Malagasy to have a chance and give their population time to expand.
IMHO you'd need a more politically fragmented Indian Ocean, no rise of British hegemony. This would not only allow Madagascar to play off continuing rivalries but also to attempt to do a Sardinia, send an expeditionary force allied to one of the competing powers to take part in some regional conflict, that will never threaten its own actual homeland.
If, for example, powers are competing in India, and there are wars led by the powers, including regional allies, well into the later 19th century, then Madagascar can play them off for what it can gain, then for example send an expeditionary regiment to, say help the British against a Russian incursion into Baluchistan, or help the French against a Dutch-led thrust on Pondicherry from the South.
I don't think they'd have the resources to support any expedition on that level, at most they could maybe send a ship. Anything beyond the Maldives would probably be impossible for the Malagasy to seriously try and take part in.
But Madagascar is a strategic island, especially for a power like France with interests in the Far East but no ports on the Cape thanks to their rival Britain. They'd need to play France off Britain and later Germany (ideally Germany) to get anywhere. I think this sets them down a course of war with Portugal, since both France and Germany want to expand their interests in East Africa, Portugal is a British ally, and the Malagasy would want to be recognised as a modern and successful empire so would want to take some or all of Portuguese Mozambique. Hell, even Britain might not care much if it's after the Pink Map and could support it as a way of punishing the Portuguese.
Now yes, this is the era of scientific racism, but the Malagasy and in particular the Merina could actually benefit from that (and would argue for it themselves) by pointing out that the Merina elite are actually of the "Malay race" (term used back then) which "naturally dominate the lesser negroes of Madagascar" (to put it in terms used by someone from that era). A victory over Portugal can be chalked up to the inferior racial quality of Portuguese colonial soldiers compared to "partly Asiatic" Malagasy soldiers or of the Portuguese themselves who are "the most African of the Mediterranean race" or some other nonsense. This is probably the one advantage of a Merina unification of Madagascar since they can use European racism to their advantage unlike the Sakalava or another group where there would need to be an "explanation" why dark-skinned elite owned so many lighter-skinned slaves (as happened at times IOTL).
I'd give Portugal the advantage in a hypothetical 1890s-1900s war since they'd be on the defensive, but this is the sort of war which is won and lost by a single naval battle. Assuming the Merina train their gun crews well and get halfway decent ships from Germany or France (French battleships in that era were utterly weird, but the Malagasy can't afford them and would probably buy cruisers instead) they'd probably be able to squeeze out a victory and bankrupt themselves in the process.
Madagascar would essentially be a naval-focused version of Thailand.
Did Portugal have any desire to be in that island and did the Marina have any claims to the centuries old Portuguese ports and forts in Mozambique?
Portugal had interests in Madagascar historically, but not in the 19th century IIRC. Madagascar would probably take what they could get in Africa from Portugal even if they have as much of a claim on it as Japan had on Vladivostok.