Skip to content

Commit

Permalink
Merge pull request #58 from sanskar28/master
Browse files Browse the repository at this point in the history
Added Abbrevation in python
  • Loading branch information
championballer authored Dec 25, 2019
2 parents 34cca5a + 79834d2 commit 4dbef8f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions Dynamic Programming/Abbrevation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/python3

import math
import os
import random
import re
import sys

def abbreviation(a, b):
m, n = len(a), len(b)
dp = [[False]*(m+1) for _ in range(n+1)]
dp[0][0] = True
for i in range(n+1):
for j in range(m+1):
if i == 0 and j != 0:
dp[i][j] = a[j-1].islower() and dp[i][j-1]
elif i != 0 and j != 0:
if a[j-1] == b[i-1]:
dp[i][j] = dp[i-1][j-1]
elif a[j-1].upper() == b[i-1]:
dp[i][j] = dp[i-1][j-1] or dp[i][j-1]
elif not (a[j-1].isupper() and b[i-1].isupper()):
dp[i][j] = dp[i][j-1]
return "YES" if dp[n][m] else "NO"

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

q = int(input())

for q_itr in range(q):
a = input()

b = input()

result = abbreviation(a, b)

fptr.write(result + '\n')

fptr.close()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ in C++, Java and Python.
|Dynamic Programming| ||||
||[Max Sum Array](https://www.hackerrank.com/challenges/max-array-sum/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=dynamic-programming)|[Done](/Dynamic%20Programming/max_array_sum.cpp)|[Done](https://github.com/maze-runnar/interview-preparation-kit/blob/master/Dynamic%20Programming/MaxSumArray.java)|[Done](/Dynamic%20Programming/MaxSumArray.py)|
||[Candies](https://www.hackerrank.com/challenges/candies/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=dynamic-programming)|[Done](/Dynamic%20Programming/candies.cpp)||[Done](/Dynamic%20Programming/Candies.py)|
| |[Abbreviation](https://www.hackerrank.com/challenges/abbr/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=dynamic-programming) |[Done](/Dynamic%20Programming/abbreviation.cpp) | | |
| |[Abbreviation](https://www.hackerrank.com/challenges/abbr/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=dynamic-programming) |[Done](/Dynamic%20Programming/abbreviation.cpp) | | [Done](/Dynamic%20Programming/Abbrevation.py)|
| |[Decibinary Numbers](https://www.hackerrank.com/challenges/decibinary-numbers/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=dynamic-programming) |[Done](/Dynamic%20Programming/decibinary_numbers.cpp) | | |
|Stacks and Queues|||||
||[Balanced Brackets](https://www.hackerrank.com/challenges/balanced-brackets/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=stacks-queues)|||[Done](/Stack%20and%20Queues/BalancedBrackets.py)|
Expand Down

0 comments on commit 4dbef8f

Please sign in to comment.