Ad
  • Default User Avatar

    As a word of caution to future professional developers:

    I'd be leery of using match with a string. This turns into a regex, which has special meaning. If array1 contained any strings with non-letter chars, like '.', the match would trip up certain tests.

    e.g. 'hello'.match('h.l.o') returns a match.

    Also, if someone were trying to be malicious, it could be worse (could potentially crash things).

    e.g. 'hello world'.match('(((((((.*)*)*)*)*)*)*)*x'), in Firefox, freezes for a few seconds.

  • Default User Avatar

    It's not clear for certain cases when and which cars the algorithm should turn away.
    For instance, given,

    [ /* 1 */[0,100], /* 2 - 7 */[5,10], [10,20], [20,40], [40,60], [60,80], [80,100] ]
    
    // 1:     | - - - - - - - - - - - - - - - - - - - |
    // 2 - 7:   | | - | - - - | - - - | - - - | - - - |
    
    

    I think Dave's gonna say no to just the first guy seeing he can then turn away only 1 vehicle instead of 6 (since the first guy would otherwise be stuck in the front). The prompt doesn't make it clear enough, though, as to what to return in this case.

    If it's made clear that the goal is to achieve the minimal value, then the puzzle becomes much more interesting (albeit a lot harder), but also requires additional tests to ensure cases like the above are satisfied correctly.

    If getting the minimum isn't required, then it really should be made clear that, for certain cases (like the above), multiple return values are accepted, as long as they don't turn anyone away unnecessarily (although, this makes generating random tests probably a bit difficult).