Page 1 of 1
Given two sentences s and t, your task is to check whether they are nested anagrams, i.e. if it's possible to rearrange
Posted: Tue Jul 12, 2022 8:15 am
by answerhappygod

- Given Two Sentences S And T Your Task Is To Check Whether They Are Nested Anagrams I E If It S Possible To Rearrange 1 (62.52 KiB) Viewed 40 times

- Given Two Sentences S And T Your Task Is To Check Whether They Are Nested Anagrams I E If It S Possible To Rearrange 2 (43.91 KiB) Viewed 40 times
Given two sentences s and t, your task is to check whether they are nested anagrams, i.e. if it's possible to rearrange the words in the sentence and the letters in the words themselves such that the sentences become the same. Note that it's not allowed to swap letters in different words, you can only rearrange the whole words within the sentence and rearrange the letters within a single word. It is guaranteed that the words in both sentences are separated with a single whitespace, and that both sentences don't start and end with a whitespace character. It is also guaranteed that each sentence contains at least one word and no more than 100 words.
Example • For s="bored cat" and t = "act robed", the output should be solution (s, t) = true . There are two words in s "bored" and "cat". The first word's letters can be rearranged to become "robed", and the second word's letters can be rearranged to become "act". When you rearrange the two new words "robed" and "act", you make the new sentence "act robed" which equals to t. For s = "aa bb" and t = "ab ab", the output should be solution (s, t) = false You can't rearrange the words and the letters in the words such that the sentences become the same so the answer is false.