All Questions
11 questions
1
vote
3
answers
52
views
`set_includes` (string subsequence-containment) in Python 2
I've implemented C++'s std::includes algorithm in Python, so that I can use it to efficiently implement a Scrabble "can I make this word" function:
...
4
votes
2
answers
1k
views
Finding palindromic strings of even length
Given a string of digits. Find the length of longest substring of even length i.e. 0,2,... which is a palindrome or which can be rearranged to form a palindrome (see example below).
Here is my code: ...
7
votes
4
answers
1k
views
Solving jumbled letters using a given dictionary
Given a dictionary, a method to do lookup in dictionary and a M x N board where every cell has one character. Find all possible words that can be formed by a sequence of adjacent characters.
Example:
...
1
vote
1
answer
995
views
The Substring Game! challenge
This is the Substring Game! challenge from HackerEarth:
Watson gives Sherlock a string (let's denote it by S). Watson calculates all the substrings of S in his favourite order.
According to ...
3
votes
3
answers
6k
views
Finding the longest palindromic substring
I have the following code that works correctly. I am wondering if there is a simpler way to go about implementing my solution and/or if there is anything that looks non-standard in my code. If anyone ...
4
votes
2
answers
721
views
Checking whether any anagram of a string appears within another string
I have the following code that takes a string t and checks to see if any anagram of t is a substring of ...
7
votes
4
answers
7k
views
Find the shortest whole repetitive substring
I'm working on a problem to find wholly repeated shortest substring of a given string, and if no match, return length of the string.
My major idea is using a Trie ...
5
votes
1
answer
111
views
Princeton KMP implementation
I implemented a Python version of KMP followed by Princeton Prof Robert Sedgewick's discussion.
However, I got a Time Limit Exceeds error. Per leetcode's explanation, TLE indicates that the solution ...
2
votes
2
answers
5k
views
Count overlapping substrings
I'm looking for feedback on the actual logic of this simple Python 2.7 script. The automated grader passed it, but I expect it could be make more 'pythonic'. It was written for homework, and some of ...
5
votes
2
answers
6k
views
Testing whether a given string has unique characters
Here is my code which tests whether a given string has unique characters. The function is_unique which does a linear search for each character in the string is \$O(...
11
votes
1
answer
4k
views
Z-Algorithm for pattern matching in strings
I was trying to refactor the following Python code (keeping the same time-complexity) which is an implementation of Z-Algorithm for pattern matching in strings.
...