Here’s my approach to the question -
- I make a hashmap of character and index
- I store all the characters of str2 onto my map with 0 as default
- I check if str1 contains the characters in the hashmap and if it does then I update the index on the hashmap with the current index
- I find the min and max values of the hashmap
- My resultant substring would be from the min index to the max index of str1
I dry run the code on my book and it’s supposed to work but the only output I’m getting is q for the given example.
Here’s my code - https://ide.codingblocks.com/s/236667