![]() |
VOOZH | about |
Change gender of string i.e toggle all the gender-specific words in the input string.
Examples:
Input: “she is my sister” Output: “he is my brother”. There are two gender-specific words in this sentence:“she” and “sister”. After toggling gender specific words to their respective counterparts - “he” and “brother” : Gender specific words of the string are now changed.
Algorithm:
he is going to watch movie with his girlfriend
Time Complexity: O(N^2), where N is the length of the string, as the ‘+’/ ‘append’ operator of the string can take upto O(N) time and assuming that lookup in the dictionary takes O(1) worse case time.
Auxiliary Space: Apart from the dictionary that maps all the words to its counterpart, we declare O(N) space for the new string, where N is the length of input string.
Scope for Improvement: