What would be the efficient approach to solve this problem :
Several car company exist in such a way that each company can control a large share of sales in different markets. You are required to perform a simulation that modifies the results after any mergers that happen between these companies.
Your task is to determine the minimum number of mergers that must be performed between the car companies to ensure that a market is controlled by no more than two separate companies.
INPUT n -> no of companies, m -> no of markets shared by each company.
next n line, where ith line contains m markets ID, controlled by company i.