5 kyu

Minimum and Maximum Product of k Elements - Advanced

72 of 113anter69
Description
Loading description...
Arrays
Lists
Performance
Algorithms
  • Please sign in or sign up to leave a comment.
  • RealKenshiro Avatar

    A truly excellent kata. Thanks @anter69.

  • FArekkusu Avatar

    Python 3.8 should be enabled.

  • Alphred Avatar

    Could someone help me with, what to do in case k is bigger than the size of vector for c++? What to return in this case? My code solves correct for examples that have k less than size.

  • FArekkusu Avatar

    C++ version generates warnings.

  • Yedya Avatar

    This comment has been hidden.

  • cyril-lemaire Avatar

    Only two complaints I have:

    • in Ruby at least (surely in Python too, and any language with automatic BigInt conversion) the array elements are Integers only and the min/max products may go way beyond Float::MIN and Float::MAX. Might be good to specify it in the description so nobody tries to multiply the thing by a float.

    • It's a detail, but judging from the test cases, k is a strictly positive integer. I wondered a bit whether I should return 1 in the case k == 0, but it was never tested. Adding it directly to the description might be clearer.

    Once again, you did a very good work on this kata series. Kudos.

  • cyril-lemaire Avatar

    That kata is really VERY GOOD! A very simple description with a quite challenging task to optimize and make a "cute" solution.

    Validation tests could be much harder though, I even thought you made a crazy version of this at first. A robust solution should handle arrays of 100,000 with k in range(1, 200) at least. I'm saying at least because I suck at optimizing and even I could do that. (I can only handle ~200 of them in Ruby, but I'm quite sure you can get up to 1000)

  • xavierguihot Avatar

    Decription's link to Minumum and Maximum Product of k Elements is dead.

  • Blind4Basics Avatar

    This comment has been hidden.

  • Blind4Basics Avatar

    Mmmmh.. Two solutions have been wiped out. Is that due to an intentionnal modification? If not, you should seek for the related edge cases ;)

  • raulbc777 Avatar

    The kata is very interesting but it needs further instructions. For example, the array input: may it have repeated elements? Because that will change the solution (comparing the previous kata). Also it would be good to know the maximum values for the tests:

    -maximum value of k

    -maximum absolute values for the integers in the array

  • Blind4Basics Avatar

    your fixed tests are "vulnerable" to input mutation (not that they could be bypassed, but a user could end up having troubles if he mutates the input).

  • Blind4Basics Avatar

    you should push the things way harder, IMO (my current solution is 4 times faster than yours (using N_TEST=800 in a fork, without the it/assert_equals).