Given two strings, the task is to check whether the frequencies of a character(for each character) in one string is a multiple or a factor in another string. If it is, then output “YES”, otherwise output “NO”.
Input: s1 = “aabccd”, s2 = “bbbaaaacc”
Frequency of ‘a’ in s1 and s2 are 2 and 4 respectively, and 2 is a factor of 4
Frequency of ‘b’ in s1 and s2 are 1 and 3 respectively, and 1 is a factor of 3
Frequency of ‘c’ in s1 and s2 are same hence it also satisfies.
Frequency of ‘d’ in s1 and s2 are 1 and 0 respectively, but 0 is a multiple of every number, hence satisfied.
Hence, the answer YES.
Input: s1 = “hhdwjwqq”, s2 = “qwjdddhhh”
- Store frequency of characters in s1 in first map STL.
- Store frequency of characters in s2 in second map STL.
- Let the frequency of a chracter in first map be F1. Let us also assume the frequency of this character in second map is F2.
- Check F1%F2 and F2%F1(modulo operation). If either of them is 0, then the condition is satisfied.
- Check it for all the characters.
Below is the implementation of the above approach:
- Longest sub-string having frequency of each character less than equal to k
- Print number of words, vowels and frequency of each character
- Check if a string has all characters with same frequency with one variation allowed
- Check whether frequency of characters in a string makes Fibonacci Sequence
- Find a string such that every character is lexicographically greater than its immediate next character
- Replace every character of string by character whose ASCII value is K times more than it
- Check if both halves of the string have at least one different character
- Check if a two character string can be made using given words
- Check if max occurring character of one string appears same no. of times in other
- Python | Check order of character in string using OrderedDict( )
- Replace every character of a string by a different character
- Frequency of a substring in a string
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Remove even frequency characters from the string
- Frequency of a string in an array of strings