Skip to content

Commit

Permalink
Minimum number characters to append to a string to make it a subsequence
Browse files Browse the repository at this point in the history
of another string
  • Loading branch information
hariharanragothaman committed Jun 3, 2024
1 parent cdd5ccf commit 7535404
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions z-problems/leetcode/2486.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution:
def appendCharacters(self, s: str, t: str) -> int:
sn = len(s)
tn = len(t)

cnt = 0
for i in range(0, sn):
if cnt < tn and s[i] == t[cnt]:
cnt += 1

ans = 0 if cnt == tn else tn - cnt
return ans


if __name__ == '__main__':
obj = Solution()
s = "coaching"
t = "coding"
ans = obj.appendCharacters(s, t)
print(ans)
print(s[5])

0 comments on commit 7535404

Please sign in to comment.