Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day 7 #15

Closed
vaskoz opened this issue Aug 30, 2018 · 3 comments
Closed

Day 7 #15

vaskoz opened this issue Aug 30, 2018 · 3 comments
Assignees

Comments

@vaskoz
Copy link
Owner

vaskoz commented Aug 30, 2018

Good morning! Here's your coding interview problem for today.

This problem was asked by Facebook.

Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decoded.

For example, the message '111' would give 3, since it could be decoded as 'aaa', 'ka', and 'ak'.

You can assume that the messages are decodable. For example, '001' is not allowed.

@vaskoz vaskoz self-assigned this Aug 30, 2018
@vaskoz vaskoz mentioned this issue Aug 30, 2018
Merged
@charliecys
Copy link

Hi Vaskoz!

I believe your solution will fail on "1111127".

It should expect 13 which consist of the following:
aaaaabg, aaakbg, aakabg, akaabg, kaaabg, kkabg, kakbg, akkbg, aaaalg, aaklg, akalg, kaalg, kklg

@vaskoz
Copy link
Owner Author

vaskoz commented Apr 3, 2019

Hi @charlieysc !

I added your testcase to my "day 7" tests with this commit and the test appears to pass on your testcase with the code as-is.

Separately, I also rewrote my solution to make it easier to read. My previous solution processed the input from the back. My new solution processes the input from the front.

The simplification also resulted in a small speedup.
BEFORE:

go test -cover -race -bench=.                                              
goos: darwin
goarch: amd64
pkg: github.com/vaskoz/dailycodingproblem-go/day7
BenchmarkNumberOfDecodings-12    	  200000	     10726 ns/op
PASS
coverage: 100.0% of statements
ok  	github.com/vaskoz/dailycodingproblem-go/day7	3.280s

AFTER:

go test -cover -race -bench=.
goos: darwin
goarch: amd64
pkg: github.com/vaskoz/dailycodingproblem-go/day7
BenchmarkNumberOfDecodings-12    	  200000	      9388 ns/op
PASS
coverage: 100.0% of statements
ok  	github.com/vaskoz/dailycodingproblem-go/day7	3.000s

@charliecys
Copy link

Whoops! Mistake on my part. Yes, your solution works as-is.

@vaskoz vaskoz mentioned this issue Mar 7, 2020
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

No branches or pull requests

2 participants