Skip to content

Conversation

@thatguyintech
Copy link
Owner

plz comment with thoughts, criticisms, anything! :)

@thatguyintech
Copy link
Owner Author

atm the code is not finished, today was a long day and I couldn't bring myself to finish the code. But the thougth process is all there and it's not too complex.


there are only 4 possible starting locations: `(0, 0), (0, 1), (1,0), (1,1)`.

I don't think it's possible to do this problem and faster. So it's not
Copy link

@jjwon0 jjwon0 Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I haven't seen or done this problem before, so this might be totally wrong.

This problem reminds me a lot of fast string matching, which means that there's probably a faster way to do it. In KMP and other linear string search algorithms, a key observation is that you might be able to skip steps. For example,

needle = 'abcd'
haystack = 'abcfffffabcdffffff'

When we compare by eye, we notice that the first three characters of needle and haystack match, but the fourth doesn't. Subsequently, we skip ahead when looking, because we know that the fourth character was an f, but needle[0] != 'f', so we can jump a few characters ahead. Specifically, we can start searching again from haystack[4:].

I suspect something similar can work in this problem, which would give it ultimately a runtime of O(nm), where n and m are the dimensions of the big matrix.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

damn uR RIGHT

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't done thorough research yet, but it seems like this one also generalizes well to two-dimensional patern matching https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm

@thatguyintech thatguyintech merged commit 96f413a into master May 4, 2017
@thatguyintech thatguyintech deleted the day14 branch May 4, 2017 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants