human
What is a code to check if frequency of each character is equal to its position in English Alphabet and the other steps required given the following:
Check if frequency of each character is equal to its position in English Alphabet | Python3 program for the above approach.
Initialise frequency array.
Traverse the string.
Update the frequency.
Check for valid string.
If frequency is non - zero.
If freq is not equals to ( i + 1 ) , then return false.
Return true.
Given string str"
Solution in Python:
assistant
#Here is code to check if frequency of each character is equal to its position in English Alphabet and the other steps required.
 def checkValidString ( str ) :
	freq = [ 0 for i in range ( 26 ) ]
	for i in range ( len ( str ) ) :
		freq [ ord ( str [ i ] ) - ord ( ' a ' ) ] += 1
	for i in range ( 26 ) :
		if ( freq [ i ] != 0 ) :
			if ( freq [ i ] != i + 1 ) :
				return False
	return True
str = " abbcccdddd "
if ( checkValidString ( str ) ) :
	print ( " Yes " )
else :
	print ( " No " )