My code link:
If possible please give counter example.
add to map and count frequency.
match the same and add score to final_score add remaining will be added to vector v
calculate score of every pair from v and if score is >0 add to vector score along with ids of string
sort vector score based on scores
take pair by pair untill all is selected or all pairs are checked