Duplicate Baby Names Problem
Given two lists, one of names/frequencies and other of pairs of equivalent names (synonyms), implement an algorithm to print a new list of the true frequency of each name.
Note: Name relationship is both transitive and symmetric.
Solution:
- There are various ways to solve this problem
- Using disjoint set
- Graph
Graph Implementation Algorithm:
- Create a undirected graph with node (name, frequency)
- Add edges between nodes of graph using synonyms
- Use DFS to add all frequencies of same names
Latest Source Code:
Github: BalancedBSTZeroSumFinder.java
Output:
Kris - 36 Johnny - 27