Not sure if it matches your scenario, but if it helps also looks like this solution Unique names from a list of several duplicates - #9 by shishir may be in-line with what you’re asking for
Not sure if it matches your scenario, but if it helps also looks like this solution Unique names from a list of several duplicates - #9 by shishir may be in-line with what you’re asking for