We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
See,
if(sum means there are elements in A which are not matched with B. So max you can change only 1 element in B, here you can directly return sum+1.
And else case(i.e. sum==n), means A==B(all elements in A matching with B). In this case we would have directly returned sum, but contraint on problem says : you must change one element in B( so here we will lose one pair). That's y returning sum-1.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Pairs
You are viewing a single comment's thread. Return to all comments →
See, if(sum means there are elements in A which are not matched with B. So max you can change only 1 element in B, here you can directly return sum+1.
And else case(i.e. sum==n), means A==B(all elements in A matching with B). In this case we would have directly returned sum, but contraint on problem says : you must change one element in B( so here we will lose one pair). That's y returning sum-1.