# For the purposes of this interview, imagine that we own a store. This
# store doesn't always have customers shopping: there might be some long
# stretches of time where no customers enter the store. We've asked our
# employees to write simple notes to keep track of when customers are
# shopping and when they aren't by simply writing a single letter every
# hour: 'Y' if there were customers during that hour, 'N' if the store
# was empty during that hour.
# For example, our employee might have written "Y Y N Y", which means
# the store was open for four hours that day, and it had customers
# shopping during every hour but its third one.
# hour: | 1 | 2 | 3 | 4 |
# log: | Y | Y | N | Y |
# ^
# |
# No customers during hour 3
# We suspect that we're keeping the store open too long, so we'd like to
# understand when we *should have* closed the store. For simplicity's
# sake, we'll talk about when to close the store by talking about how
# many hours it was open: if our closing time is `2`, that means the
# store would have been open for two hours and then closed.
# hour: | 1 | 2 | 3 | 4 |
# log: | Y | Y | N | Y |
# closing_time: 0 1 2 3 4
# ^ ^
# | |
# before hour #1 after hour #4
# (A closing time of 0 means we simply wouldn't have opened the store at
# all that day.)
#
n extract only one valid log, "BEGIN Y Y END". For our
purposes, we should ignore any invalid log. *A valid log cannot contain a
nested log. (i.e. Valid logs cannot be nested.) Valid logs can span multiple lines.
Also there can be multiple valid logs on a single line.*
Write a function `get_best_closing_times` that takes an aggregate log
as a string and returns an array of best closing times for every valid
log we can find, in the order that we find them.
Do some simple testing, and then quickly describe a few other tests
you would write given more time.
## Examples
get_best_closing_times("BEGIN Y Y END \nBEGIN N N END")
should return an array: [2, 0]
get_best_closing_times("BEGIN BEGIN \nBEGIN N N BEGIN Y Y\n END N N END")
should return an array: [2]