MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / abbr

Function abbr

dynamic_programming/abbreviation.py:15–33  ·  view source on GitHub ↗

>>> abbr("daBcd", "ABC") True >>> abbr("dBcd", "ABC") False

(a: str, b: str)

Source from the content-addressed store, hash-verified

13
14
15def abbr(a: str, b: str) -> bool:
16 """
17 >>> abbr("daBcd", "ABC")
18 True
19 >>> abbr("dBcd", "ABC")
20 False
21 """
22 n = len(a)
23 m = len(b)
24 dp = [[False for _ in range(m + 1)] for _ in range(n + 1)]
25 dp[0][0] = True
26 for i in range(n):
27 for j in range(m + 1):
28 if dp[i][j]:
29 if j < m and a[i].upper() == b[j]:
30 dp[i + 1][j + 1] = True
31 if a[i].islower():
32 dp[i + 1][j] = True
33 return dp[n][m]
34
35
36if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected