Given two strings validate the output string
Objective: Given two input strings and one output strings, validate if output string contains all the characters from both the input strings.
Input1 = "boy", Input2 = "girl", output = "gboilry" Result = True Input1 = "tutorial", Input2 = "horizon", output = "tuhotoririzoialn" Result = True Input1 = "boy", Input2 = "girl", output = "bogiry" Result = False
- Create a one Hash Map using both the input strings with character as key and its count as value.
- Iterate through output string and check the each character in map and if exist then reduce its count and if does not exist then return false.
- At the end iterate through map and check the count of each character, if any of the count is not 0 then return false.
- If none of the previous steps returned false, return true.
input1: boy input2: girl Output String: gboilry true input1: boy input2: girl Output String: gboily false
Top Companies Interview Questions..-
If you find anything incorrect or you feel that there is any better approach to solve the above problem, please write comment.