We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defabbreviation(a,b):# Write your code heredp=[[1]+[0]*(len(b))foriinrange(len(a)+1)]# dp[i][0] always 1('YES') cuz b got 0 lengthforiinrange(1,len(a)+1):forjinrange(1,len(b)+1):ifa[i-1]==b[j-1]:# same upper casedp[i][j]=dp[i-1][j-1]elifa[i-1]==b[j-1].lower():# same lower casedp[i][j]=max(dp[i-1][j-1],dp[i-1][j])elifa[i-1].isupper():dp[i][j]=0else:dp[i][j]=dp[i-1][j]ifdp[len(a)][len(b)]:return'YES'else:return'NO'
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Abbreviation
You are viewing a single comment's thread. Return to all comments →
Python 3 solution