Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
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. ...
SohamC's user avatar
  • 221
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 ...
Lin Ma's user avatar
  • 3,453
0 votes
2 answers
2k views

JSON string parsing

I need to parse a simple JSON string (flat JSON, no hierarchy) for keys and values, and there is a system constraint that I cannot use any built-in JSON library and can only read a string once due to ...
Lin Ma's user avatar
  • 3,453
18 votes
2 answers
1k views

Given a page of content, determine shortest snippet containing all search phrases (no order required)

A recruiter gave me a homework problem as a part of the recruiting process and after receiving my submission he told me that he decided not to proceed with me. When I asked for the reason, he told me ...
ATT's user avatar
  • 183
8 votes
2 answers
4k views

Finding words that rhyme

Preface I was trying to review this question on the same topic, but in the end many points I wanted to make were excellently explained by @ferada so I felt that posting my code and explaining the ...
Caridorc's user avatar
  • 27.6k
8 votes
3 answers
4k views

Function to censor single word in a sentence

The following function censors a single word of choice in a sentence with asterisks, regardless of how many times the word appears. How can I further simplify this code? ...
hseek's user avatar
  • 171
7 votes
1 answer
134 views

Zalera calculator

I recently started replaying Final Fantasy XII. One of its optional bosses, Zalera, has, among others, the following mechanics: His attack sequence is Lv. 2 Sleep, Lv. 3 Disable, Lv. 4 Break and Lv. ...
Mast's user avatar
  • 13.5k
7 votes
3 answers
3k views

Finding the fastest common prefix of 2 strings in Python

I'm comparing my algorithms, slice_prefix and bit_prefix, with existing ones to find the common prefix length of 2 strings as ...
12345678910111213's user avatar
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(...
CodeYogi's user avatar
  • 5,127
5 votes
2 answers
2k views

Numbers to Text Program - Python Training

I have written a numbers to text challenge for some people in my organisation to practice their Python skills. I am an economist working with pandas, but I am trying to teach them some stuff about ...
Woody Pride's user avatar
4 votes
1 answer
292 views

High execution time to count overlapping substrings

I was doing this HackerRank problem which basically boils down to counting overlapping substrings in a string. I used this solution from StackOverflow to build this program - ...
Sidharth Samant's user avatar
2 votes
2 answers
985 views

Speeding up and fixing phone numbers from CSVs with Regex

I've hodgepodged together an attempt to extract all phone numbers from all CSVs in a directory, regardless of where they are and what format they're in. I want all phone numbers to be printed to a ...
Xodarap777's user avatar