Ad
  • Custom User Avatar

    Hey,

    Thank you very much for your help. Your hints helped me a lot to solve the exercise. I’ve just made the MITx 6.00.1x course on edX, and the last chapter was about the Big Oh notation. In that chapter was some key information, without that, and your help I do not know how I could solve the problem. Yeah that now I solved the problem the code does not seem to complex, and it could be 6 kyu, but the requirements to solve this I still do not think it’s the 6kyu level. But anyway, it was extremely rewarding this challenging problem to solve.

  • Custom User Avatar

    Hello there, I'm just leaving this reply in case someone struggles with the code timing out.

    To solve this problem you generally CAN'T use higher order array methods inside ANY loop (in Javascript the methods used for this case are generally Map or Reduce). Calling Higher-Order Array methods inside a loop will make the time to execute the code significantly higher, and the solution will fail.

    • You CAN'T use NESTED LOOPS (that's implied by the last point). Perhaps a solution using nested loops can still pass the tests, but it's far from optimal and it's not the point of the Kata. The Kata has huge test cases because it's testing if you can make your code efficient enough.

    • You CAN use two different loops that aren't nested, and most common solutions would use this.

    • You also CAN do simple operations inside a loop, like substracting or adding numbers, or pushing a value to an existing array. You can do simple operations like this which don't involve creating new arrays or looping through the totality of an existing array.

    This Kata seems like a 6 Kyu to me but it may require some previous knowledge of Big O Notation and Time Complexity to understand why some solutions work and why some don't. Having an awareness of Big O Notation can make all this very clear, and I encourage any programmer to research this topic.

    Here's a video that might be very useful to get anyone started.

  • Custom User Avatar

    You don't need to use a generator. My solution was actually bone simple. Try thinking about how you can tally what you need and add to a list as you read through the input list.

  • Custom User Avatar

    Please give me a hint. I am struggle with this solution since days, I can't sleep... :D

    I trying to solve the problem with generator, but don't know how. My code always timeout. I returning a list, which all elementa are the generator next() "item". But still time out. It seems me to doesn't matter what I code until I return a list at the end, but I have to return a list to solve this kata...please help or give a hint I totally confused.
    Anyway this kata in my opinion far way harder than 6 kyu....