We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
it is (too slow) working thanks to the fact, if strings s1 and s2 have equal length.
If not -> key error
your bug: you need to build your lcs table based on len (s2) (which is l2)
hint beside: you have defined l1 and l2, but every time you could use it you write len (s1) instead of just l1 - same for l2, s2
your lcs_letters part, which is marked as comment is terribly wrong.
instead of just collecting strings in your lcs_letters you need to collect list of strings (there are more results with same length). if you found matching character you need to add it to each collected string.
xou need to separate left > above, left < above and left == above
if left == above you need to merge collected string lists (f.e. list(set(left + above)
i changed all that and more and now it not only passes this challenge, it is useful, because not only returning a number of result, also the specific results in detail .... maybe later on this might be useful to have he he :=)
Here we go:
my python3 solution also with complete list of solutions with same length for lcs_letters (i might be the only one solving it with python3), which you can see, if you solved the challenge. If you did not solve only because of timeout put your code to a pypy3 window and zoooooom, solved :)
https://www.hackerrank.com/challenges/common-child/submissions/code/115183048
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Common Child
You are viewing a single comment's thread. Return to all comments →
it is (too slow) working thanks to the fact, if strings s1 and s2 have equal length. If not -> key error your bug: you need to build your lcs table based on len (s2) (which is l2) hint beside: you have defined l1 and l2, but every time you could use it you write len (s1) instead of just l1 - same for l2, s2 your lcs_letters part, which is marked as comment is terribly wrong. instead of just collecting strings in your lcs_letters you need to collect list of strings (there are more results with same length). if you found matching character you need to add it to each collected string. xou need to separate left > above, left < above and left == above if left == above you need to merge collected string lists (f.e. list(set(left + above) i changed all that and more and now it not only passes this challenge, it is useful, because not only returning a number of result, also the specific results in detail .... maybe later on this might be useful to have he he :=)
Here we go: my python3 solution also with complete list of solutions with same length for lcs_letters (i might be the only one solving it with python3), which you can see, if you solved the challenge. If you did not solve only because of timeout put your code to a pypy3 window and zoooooom, solved :) https://www.hackerrank.com/challenges/common-child/submissions/code/115183048