File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ https://www.hackerrank.com/challenges/abbr/problem
3
+ You can perform the following operation on some string, :
4
+
5
+ 1. Capitalize zero or more of 's lowercase letters at some index i
6
+ (i.e., make them uppercase).
7
+ 2. Delete all of the remaining lowercase letters in .
8
+
9
+ Example:
10
+ a=daBcd and b="ABC"
11
+ daBcd -> capitalize a and c(dABCd) -> remove d (ABC)
12
+ """
13
+ def abbr (a , b ):
14
+ n = len (a )
15
+ m = len (b )
16
+ dp = [[False for _ in range (m + 1 )] for _ in range (n + 1 )]
17
+ dp [0 ][0 ] = True
18
+ for i in range (n ):
19
+ for j in range (m + 1 ):
20
+ if dp [i ][j ]:
21
+ if j < m and a [i ].upper () == b [j ]:
22
+ dp [i + 1 ][j + 1 ] = True
23
+ if a [i ].islower ():
24
+ dp [i + 1 ][j ] = True
25
+ return dp [n ][m ]
26
+
27
+
28
+ if __name__ == "__main__" :
29
+ print abbr ("daBcd" , "ABC" ) # expect True
You can’t perform that action at this time.
0 commit comments