Ad
  • Custom User Avatar

    Use divide and conquer approach...

  • Custom User Avatar

    True but this doesnt't work, wouldn't pass any tests and doesn't conform to the tests

  • Custom User Avatar

    using System.Linq;class M{static T x(params T[]p)=>p.Max();}

  • Custom User Avatar

    You're right, vectorMax should be initialized to that to account for negatives.

    Copying the vectors isn't an issue. You need two vectors to intrinsically compare two vectors. Doing this alone already compensates for the time spent copying some memory around. Memory is cheap. In fact, doing most things in C# involve allocating memory. A foreach loop even creates copies of values.

    From benchmarks I have done a while ago, this method of comparing values in an array is magnitudes faster than any scalar method.

  • Custom User Avatar

    You iterate through every vector which would not any faster than copying a very small block of memory after using abstracted intrinsics to compare two vectors. Under the hood, the Max method allows for "jit intrinsic expansions" so you should save the entirety of the compared vectors until you're done with vectors

  • Custom User Avatar

    Thanks for explaining your choices :)

  • Custom User Avatar

    var vectorMax = Vector<int>.Zero; but var vectorMax = Vector<int>(int.MinValue); should be, I think

    var blockVector = new Vector<int>(nums, blockIndex); copy memory

    vectorMax = Vector.Max(vectorMax, blockVector); copy memory

    2 memory coping. Is it faster then classic loop?

  • Custom User Avatar

    if (items == null || items.Length == 0) C# compiler makes check on null them self, so if (items.Length == 0) is enought.
    max = items[i].CompareTo(max) > 0 ? items[i] : max; is slower then if (max.CompareTo(items[i]) < 0) max = items[i];

    I love var more then T because code can be copied and paste to another place without changing.

  • Default User Avatar

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

  • Default User Avatar

    C translation (author gone)

    It even has random tests !

  • Default User Avatar

    added

  • Default User Avatar

    added useful error messages to JS

  • Default User Avatar

    tests now use assert_equals

  • Default User Avatar

    1000 Go completions so it's unlikely that the tests would crash

  • Default User Avatar

    fixed for python

  • Loading more items...