Skip to content

Commit 8cefa4c

Browse files
Aadit KamatMadhavBahl
authored andcommitted
Python Implementation of Day 11 problem (CodeToExpress#115)
* Add @aaditkamat as a contributor * Add Ruby code for Day 1: FizzBuzz problem * Add Ruby code for Day 2: String reverse problem * Update README.md for Day 2 * Modify Ruby code and README * Add condition for nil and wrong type edge cases * Add a seperate Ruby source code file for palindrome * Modify code for reverse.rb * Add seperate palindrome and reverse code sections in README * Update gitignore * Refactor palindrome.rb and rename heading in README * Add solution for Day 3: Hamming Problem * Add condition for strings of unequal lengths * Update README * Change project name and owner in.all-contributorsrc * Remove merge conflict lines * Add @shivank86 as a contributor * Add C++ files for different patterns * Add author and date comments at the top of C++ files * Update README.md * Add solution for Day 6 Problem in Python * Update README * Refactor code files * Modify string representation of output in python files * Add Ruby solutions for Day 6 problem * Update README for Ruby code * Add first version of solutions for Day 7 problem in C++, Java & Ruby * Modify solutions * Update Day 7 README * Remove merge conflicts from CONTRIBUTORS.md * Add back removed lines in CONTRIBUTORS.md * Add code sections contributed by @imkaka to day 6 README * Update README.md * Add C++ solution * Add Day 8 solution in C++ * Add Day 8 solution in Java * Add Day 8 solution in Ruby * Add Day 8 solution in Python * Add credits at the top of the code * Update README * Update C++ implementation * Update Python implementation * Add solution for Day 10: String Permutation Problem in Python Signed-off-by: Aadit Rahul Kamat <[email protected]> * Update Day 10 README Signed-off-by: Aadit Rahul Kamat <[email protected]> * Change heading in README and remove empty directory in day 9 Signed-off-by: Aadit Rahul Kamat <[email protected]> * Update README.md * Add solution to Day 11 problem in Python * added code 11 (CodeToExpress#121) * day 11 (CodeToExpress#117) * Python solution for day 10 and day 11 (CodeToExpress#114) * Add @vishalshirke7 as a contributor * Update @vishalshirke7 as a contributor * Added python solutions for Day 4 * modified readme * Add @Vishal * reverted adding as a contributor * Update README.md * Update CONTRIBUTORS.md * Update CONTRIBUTORS.md * Added python solutions for day 7 * Edited python solution for day 7 * Edited python solution for day 7 * Added python solution for day 10 * Changed readme for day 10 * minor changes * Python solution for day 11 * Python solution for day10 and day11 * Add Day 10 & Day 11 - Java Implementation (CodeToExpress#116) * Update @chaitanya-bhojwani as a contributor * Java Implementation * Add day 10 and day 11 * Add day 12 * Update day 11 README Signed-off-by: Aadit Rahul Kamat <[email protected]>
1 parent 1c181f4 commit 8cefa4c

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'''
2+
@author: aaditkamat
3+
@date: 03/01/2019
4+
'''
5+
def print_output(str1, str2):
6+
print(f'The longest common substring in {str1} and {str2} is: {longest_common_substring(str1, str2)}')
7+
8+
def substrings(string):
9+
lst = []
10+
n = len(string)
11+
for i in range(1, n + 1):
12+
for j in range(n + 1 - i):
13+
lst.append(string[j : j + i])
14+
print(set(lst))
15+
return set(lst)
16+
17+
def longest_common_substring(str1, str2):
18+
str1_substrings = substrings(str1)
19+
str2_substrings = substrings(str2)
20+
common_substrings = str1_substrings & str2_substrings
21+
if len(common_substrings) == 0:
22+
common_substrings.add("")
23+
return max(common_substrings, key = lambda x: len(x))
24+
25+
print_output("abcdefg", "xyabcz")
26+
print_output("XYXYXYZ", "XYZYX")
27+
print_output("abcd", "efgh")

day11/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,36 @@ def lcs(str1, str2):
249249

250250

251251
lcs(*(input().split()))
252+
```
253+
254+
### [Solution 2](./Python/lcs.py)
255+
256+
```python
257+
'''
258+
@author: aaditkamat
259+
@date: 03/01/2019
260+
'''
261+
def print_output(str1, str2):
262+
print(f'The longest common substring in {str1} and {str2} is: {longest_common_substring(str1, str2)}')
263+
264+
def substrings(string):
265+
lst = []
266+
n = len(string)
267+
for i in range(1, n + 1):
268+
for j in range(n + 1 - i):
269+
lst.append(string[j : j + i])
270+
print(set(lst))
271+
return set(lst)
272+
273+
def longest_common_substring(str1, str2):
274+
str1_substrings = substrings(str1)
275+
str2_substrings = substrings(str2)
276+
common_substrings = str1_substrings & str2_substrings
277+
if len(common_substrings) == 0:
278+
common_substrings.add("")
279+
return max(common_substrings, key = lambda x: len(x))
280+
281+
print_output("abcdefg", "xyabcz")
282+
print_output("XYXYXYZ", "XYZYX")
283+
print_output("abcd", "efgh")
252284
```

0 commit comments

Comments
 (0)