Ad
  • Default User Avatar

    It is a good example of how lambda expressions can be used though. This solution enlarged my perspective.

  • Default User Avatar

    Thanks for making my day man xD

  • Default User Avatar

    Thanks for this great explanation

  • Default User Avatar

    Random test cases are susceptible to cheating.

  • Default User Avatar

    I have just taken off my hat...

  • Default User Avatar

    How can the result be 9 for n=12 - the last sample test for java:

    assertEquals(9, Solution.cardGame(12));

    I find the result 8 on paper. Am I wrong??

  • Default User Avatar

    This solution is not quite correct. I assume this passed the tests due to non-comprehensive test conditions. For instance consider the following case:

    f(x=3, a=3, b=5, c=3) # This is the calling function

    In the above case x must take the value "5" since its current value is "3" (Problem says: "You wish to assign to x the value other than its current one."), but the result of this solution is "3".

    The reason is that dictionaries do not allow duplicate key words. When you do {a:b, b:c, c:a} for the above test values, the value of a (3 as keyword) will be 5, and when program see that c is the same with a (in terms of keyword), instead of creating a new key-value item, it will assign a again but this time with the value of 3.
    So, the last dictionary will be {3:3, 5:3}, in which case the value "5" is unreachable which is the accual correct answer.

    I hope it helps...
    Stay safe :)