Re:Microsoft changed how it interviews software developers
by lazyasciiart on Sunday December 30, 2018 @06:06PM
(#18791877)
The question was: Write a method that can take in a regex and a string and return whether the string matches it, with the regex limited to the characters . * ?
(And backtracking is definitely where I started coming unstuck)
[ Parent
| on HN ]
Re:Microsoft changed how it interviews software developers
by thijsvandien on Sunday December 30, 2018 @08:28PM
(#18792459)
If the regex is really just a sequence of dots followed by a question mark, asterisk or nothing, thus cannot contain literals, the only thing you need to check for is the length of the string.
The minimum length will be the number of dots without a quantifier (i.e. exactly one character). If there is any dot followed by an asterisk, there is no maximum length. Otherwise, the maximum length will be the minimum length plus the number of dots followed by a question mark.
Writing the code for this is left as an exercise to the reader. ;)
Re:Microsoft changed how it interviews software developers
by lazyasciiart on Sunday December 30, 2018 @11:44PM
(#18793055)
The regex can be any string made up of any number of those three characters in any order.
Re:Microsoft changed how it interviews software developers
by senorsmile on Sunday December 30, 2018 @06:50PM
(#18792055)
Ah, that's definitely different than I understood your first post. You're writing a regex to match a given type of string. The regex parser is in the language itself, consuming what you've written and evaluating it.
Re:Microsoft changed how it interviews software developers
by lazyasciiart on Sunday December 30, 2018 @10:11PM
(#18792785)
No, I was writing the regex parsing code. The regex was one of the inputs.