Ad
  • Custom User Avatar

    rust test cases seem to be wrong

    testing(vec![(690, 1300), (87, 1310), (30, 40)], vec![(18078, 34060), (2262, 34060), (25545, 34060)]);
    

    the lcm of 1300,1310,40 is 340600
    this is different than the test case
    34060

    see: https://www.wolframalpha.com/input/?i=lcm(1300,1310,40)

  • Custom User Avatar

    i should be of size_t otherwise with a sufficiently large x your loop will never terminate. You will get a warning if compiled with -Wall : signed unsigned comparison.

    Also s does not change in the loop. The speed calculation can be hoised out leving the loop only having to calculate max_dist.

  • Custom User Avatar

    i should be of size_t otherwise you can get (with -Wall) signed unsigned comparison. Also with a sufficiently large x your loop will never terminate.

  • Custom User Avatar

    the value of s does not alter with the loop therefore you can hoist out the calculation of av_speed. i.e. use the loop to find max_section then return std::floor(3600 * max_secion / s);

  • Custom User Avatar

    The calculation of V is being discarded in every loop. the value of S does not change in the loop. Move calculation of V to outside of the loop after finding max delta.

  • Custom User Avatar

    this requires O(n) extra space. This can be done using O(1) extra space.

  • Custom User Avatar

    unused local variable speed