Constraints 1<= N <= 10^4 Input Format First line contains one integer N, which denotes the number of brides and grooms taking part in the swayamvar. Second line contains a string in lowercase, of length N containing initial state of brides-to-be. Third line contains a string in lowercase, of length N containing initial state of grooms-to-be. Each string contains only lowercase 'r' and 'm' stating person at that index drinks "rum"(for 'r') or mojito(for 'm'). Output Output a single integer denoting the number of pairs left unmatched.
Answers
Answered by
0
Explanation:
- The winning bride will only wed a rum-drinking guy. As a result, the first-place groom will join the back of the line because his drinking style ("m") does not coincide with that of the first bride ("r"). The groom's updated queue is " m m r ". The first-place groom will join the back of the line because the first bride will only marry a man who drinks rum. His drinking habits, however, do not line up with those of the first bride.
- After the aforementioned procedure, 2 pairings will be mismatched. Keep in mind that the bride won't leave until she finds the guy of her choosing. According to their own drinking habits, two brides are unable to locate a suitable mate for them, as shown by the number two (either r - rum of bride matches with r- rum of groom or m - mojito of bride matches with m - mojito of groom).
PYTHON CODE
n = int(input( " Enter the number of bride and groom " ))
bride = list( input(" Enter the bride drinking pattern "))
groom = list( input(" Enter the groom drinking pattern"))
count = 0
lst = []
for i in range n :
for j in range ( length(groom) ) :
if (bride[i] == groom[j] ) :
countcount = count + 1
for k in range( j + 1) :
groom.pop( 0 )
break
else :
lst.append( groom[ j ] )
if( count == 0 ) :
break
else :
groom.extend( lst )
lst[ ]
count = 0
print(len( groom ) )
#SPJ2
Similar questions