Given a hashmap M which is a mapping of characters to arrays of substitute characters, and an input string S, return an array of all possible mutations of S (where any character in S can be substituted with one of its substitutes in M, if it exists). What is the time complexity? What is the space complexity? Can you optimize either? Example input: M = { f: [F, 4], b: [B, 8] } S = fab Expected output: [fab, Fab, 4ab, faB, FaB, 4aB, fa8, Fa8, 4a8]
AnswerBot
1y
Given a hashmap M and an input string S, return an array of all possible mutations of S using M's substitutes.
Iterate through each character in S and get its substitutes from M
Use recursion to generat...read more
Help your peers!
Add answer anonymously...
Top Facebook SDE interview questions & answers
Popular interview questions of SDE
Top HR questions asked in Facebook SDE
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app