Ad
  • Custom User Avatar

    There is quite good solution, but it isn't consider values such as:

    • for s = 6
    • v1 = -12
    • v2 = -18

    So, 6 can be found by (-12 - -18) for example...

  • Custom User Avatar

    lets make a variable you think?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    However, going North, then West, then South, then East... doesn't it mean that you just return exactly where you started so the final result for the easiest path should actually be [] ?

  • Default User Avatar

    I'm unable to get anywhere on the JavaScript implementation. Can we please have a complete view of the Node class/object implementation? Neither node.next or node.getNext() appear to be doing anything. Also, the nodes have no values, as near as I can tell. Which could be the issue with trying to determine if the next are doing anything.

  • Default User Avatar

    These nodes apparently have no values or identifying properties. I can't tell if my attempts to increment them is working at all. This description really needs more info on how to use these nodes.

  • Default User Avatar

    Contrary to vincaslt's comment, I believe n is necessary in order to catch the condition vectorjohn points out.

  • Default User Avatar

    I wonder what the time difference is though. Its probably the same, depending on push() implementation. Using the length to determine the next index should be O(1), right? I guess if they're the same time complexity, push is a LITTLE clearer. I still love the solution though.

  • Default User Avatar

    I used reduce. Look at my solution if you'd like to see an example.

  • Default User Avatar

    This solution is beautiful. Well done.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Hmmm, I didn't notice that info either. The problem statement is such a mess I didn't get that far down. I cant help but think the problem statement could be re-written so the problem's definition of 'needless' is made clearer, earlier. Otherwise the spirit of the premise for the problem (trying to remove all unnecessary directions) confuses people.

  • Custom User Avatar

    From the description:

    Write a function dirReduc which will take an array of strings and returns an array of strings with the needless directions removed (W<->E or S<->N side by side).

    In ["NORTH", "EAST", "WEST", "SOUTH", "WEST", "WEST"], "NORTH" and "SOUTH" are not directly opposite but they become directly opposite after the reduction of "EAST" and "WEST" so the whole path is reducible to ["WEST", "WEST"].

    Not all paths can be made simpler. The path ["NORTH", "WEST", "SOUTH", "EAST"] is not reducible. "NORTH" and "WEST", "WEST" and "SOUTH", "SOUTH" and "EAST" are not directly opposite of each other and can't become such. Hence the result path is itself : ["NORTH", "WEST", "SOUTH", "EAST"].

    So:

    The problem statement makes it seem like you want ALL superfluous directions removed

    No, the instructions state clearly that's not the case.

    The problem is people don't read the instructions well enough, and start to write code with what they think they should do instead of what they really should do. Also, they don't read the posts already written here, and open new issues.

  • Loading more items...