Ad
  • Custom User Avatar

    The issue lies with how you emulate the loop indices. You're conflating the condition evaluation count with the loop body execution count. The first loop executes 5 times, and not the 6 you have. The second loop also executes five times only, and not 6. The condition is evaluated 6 times, but not the loop body. Since you're trying to emulate what's going on, you should make sure every loop apart from the last one only counts the number of loop body executions - the innermost loop should be the only one that executes +1 more time. Correct these and you'll correctly emulate the 125.

  • Default User Avatar

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

  • Custom User Avatar

    The last loop's condition will be checked 5 times since it's inclusive. It's enclosed within a loop that executes (from here on we consider loop body executions NOT condition executions) 5 times. THAT loop is enclosed in a loop that executes 5 times. The result is the multiplication of all of those: 5 * 5 * 5 = 125.

  • Default User Avatar

    can someone please explain the kata? I don't seem to get why the [6, 30, 125 is] is correct answer for the test [(4, True), (5, False), (3, True)] I understand where does 6 and 30 comes from, however, I don't understand why 125? Because in my opinion it should be 180. No?

  • Custom User Avatar

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

  • Default User Avatar

    my code failed in one test, when the uniqe item is right in the beginning or at the end of the array. Have you guys seen it? How to deal with this?

  • Default User Avatar

    IMO you should write whatever matches the idea you have. With time and practice you pick up shorter ways to describe what you have in mind.

    Python list comprehension tends to be faster than the equivalent for-loop, but that is probably not the reason why people are choosing to use it.

    You are re-implementing some common patterns, min and map. When you start recognizing them, you might start using the already existing implementations instead.

    List comprehension combines the functionality of map and filter, but the filter part isn't needed here and the mapping function already exists - that makes map the minimal already existing thing that fits the problem.

  • Default User Avatar

    This is how I solved the kata, however I see that others use much more shorter code. Mostly they are returning list comprehension. So my question is about efficiency. Is returning one line list comprehension considered more effective?

  • Default User Avatar

    xrange() was removed in Python 3, how this code passed the test?