human
Write me a code to weighted sum of the characters of a string in an array and the other steps required given the following:
Weighted sum of the characters of a string in an array | Set 2 | Function to return the required string score.
create a hash map of strings in str.
Store every string in the map along with its position in the array.
If given string is not present in str [ ].
Multiply sum of alphabets with position.
Driver code"
Solution in Python:
assistant
#Here is code to weighted sum of the characters of a string in an array and the other steps required.
 def strScore ( string , s , n ) :
	m = { }
	for i in range ( n ) :
		m [ string [ i ] ] = i + 1
	if s not in m . keys ( ) :
		return 0
	score = 0
	for i in range ( len ( s ) ) :
		score += ord ( s [ i ] ) - ord ( ' a ' ) + 1
	score = score * m [ s ]
	return score
if __name__ == " _ _ main _ _ " :
	string = [ " geeksforgeeks " , " algorithms " , " stack " ]
	s = " algorithms "
	n = len ( string )
	score = strScore ( string , s , n ) ;
	print ( score )