How to Concatenate the given n strings to make a single string such that on combining two strings the last character of first string should be same as the first character of next string.
For example: Input: ab2c,h23f2,c4dsh Output: ab2cc4dshh23f2
I tried using hashmap is there any better solution? I cannot be able to handle some cases like Input: ab2c,h23fc,c555ab,c4dsh, Output: ab2cc4dshh23fcc555ab
In the above example there are 2 possibilities for 2nd string but taking c555ab will lead to end of string. If there are many possibilities at different levels how to handle them so as to get the correct ans?