Ad
  • Custom User Avatar

    It's not a problem in the tests, try calling your function locally like in the tests, that is, one after the other:

    print(longest_slide_down([[3], [7, 4], [2, 4, 6], [8, 5, 9, 3]]))
    print(longest_slide_down([
                [75],
                [95, 64],
                [17, 47, 82],
                [18, 35, 87, 10],
                [20,  4, 82, 47, 65],
                [19,  1, 23, 75,  3, 34],
                [88,  2, 77, 73,  7, 63, 67],
                [99, 65,  4, 28,  6, 16, 70, 92],
                [41, 41, 26, 56, 83, 40, 80, 70, 33],
                [41, 48, 72, 33, 47, 32, 37, 16, 94, 29],
                [53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14],
                [70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57],
                [91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48],
                [63, 66,  4, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31],
                [ 4, 62, 98, 27, 23,  9, 70, 98, 73, 93, 38, 53, 60,  4, 23],
                ]))
    

    And see what you get.

  • Custom User Avatar

    Have you tried locally calling your function more than once? The problem is, memo isn't reset, it keeps its value. Also point being a concatenation of x + y, how would you distinguish between '11' + '10' and '111' + '0'?

  • Custom User Avatar
  • Custom User Avatar

    And what's the code that does that?

  • Custom User Avatar

    You need to take 2 chairs from the first room, that's why the right answer for the first case is [2].
    The same for the other case, you take 4 chairs from the first room.

    "Game On" is for the case when you literally don't need chairs, like in the sample tests:

    test.assert_equals(meeting([["XX", 2], ["XXXX", 6], ["XXXXX", 4]], 0), "Game On")
    
  • Custom User Avatar

    If I am not wrong, Unnamed was using a mathematical approach and it levarages the periodicity of the sequence in terms of odd and even terms. While most of us is using iterative approach.The provided solution is more efficient for larger values.

    Regarding you question:

    1. First part (n mod 6)
      If you know the parity of two numbers, you also know the parity of their sum. So the sequence is defined as: f(n) = f(n-1)+f(n-2)+f(n-3)+f(n-4)+f(n-5)
      Initial values: f(0)=0, f(1)=1, f(2)=1, f(3)=2, f(4)=4. If you compute the parity, you will be able to see a pattern (i.e.odd, odd, even, even, even, even, odd, odd, even, even, even, even,...). So you will be able to notice the pattern repeats every 6 terms.

    2. The list [0,1,2,2,2,2],
      The above pattern (section 1) gives us the cumulative count of odd numbers.
      For n, there are (n/6) complete segments of 6 terms. Therefore, 2x(n/6) gives the number of odd terms in these complete segments.
      The remainder, n mod 6, tells us where in the 6-term segment we are. The list [0,1,2,2,2,2] gives the cumulative count of odd numbers up to that point in the cycle.

    In summary, the sequence has a repeating pattern of parity due its linear definition and the properties of of parity over addition. Therefore, this repeating pattern allowed him, Unnamed, to use a mathematical approach.

  • Custom User Avatar

    There should be no leading zero(s), unless it itself is zero.

    So in the example 'xx', it can be 11 or 10 but not 01 or 00.

    Then converted these 2 valid binary numbers to integer, you got 3 and 2, so the average is 2.5.

  • Custom User Avatar

    [5, 6, 7, 8], [5, 6, 7, 8], [6, 7, 8, 9]

    Both tests are fine. The numbers should be consecutive within each group.

  • Custom User Avatar

    It's a solution of a programmer knowing his language.

  • Custom User Avatar

    index make the time complexity "bad" (if there is a lot of elements, otherwise you won't see the difference)

  • Custom User Avatar

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