Ad
  • Custom User Avatar

    Sorry, I hardly go to Codewars.

    Your solution is incorrect. The numbers are very large and your solution may recurs v*n times. So your program will get a stack overflow.

    The time complexity of the solution is O(n log n). Think more!

  • Default User Avatar

    I get a StackOverflow in the random test.

    initialize(162885419, 466186498, 933872258, 811629502, 667992515, 432551576, 949205876, 704853680, 3422664, 141706686, 604045423, 244765318, 842862197, 947000759, 36365049, 315647101, 375917747, 26944337, 902471987, 606495393, 530330727, 723920507, 970890042, 752176407, 811407105, 781601923, 117874764, 494150506, 978209469, 702343375, 317081043, 415914823, 814885566, 445607882, 500588452, 955985133, 759973185, 123922063, 268153680, 531735000, 291317065, 961067781, 894284457, 942120463, 539817027, 554818622, 475090536, 865931848, 283891628, 365487471, 627595769, 454987982, 815429371, 663018417, 435650369, 845510893, 879695638, 761182434, 11241288, 816335587, 131292454, 254352906, 82389169, 741217628, 320072976, 605641144, 888816617, 712750506, 779278564, 23206248, 187100188, 76716475, 668364297, 399325018, 497684368, 456777931, 81939279, 923641990, 379212682, 134263919, 572910917, 195978614, 63490082, 148818629, 527030061, 165066701, 888761999, 603116397, 628244953, 963686664, 99967413, 734659925, 859072940, 61212173, 512097847, 207019786, 251668531, 571320403, 436334794, 922653825);
    modify(18, 131398922);
    UndefinedBehaviorSanitizer:DEADLYSIGNAL
    ==1==ERROR: UndefinedBehaviorSanitizer: stack-overflow on address 0x7ffda174efe8 (pc 0x7f0d7b15530e bp 0xffffffffffffff68 sp 0x7ffda174efe0 T1)
    ==1==WARNING: invalid path to external symbolizer!
    ==1==WARNING: Failed to use and restart external symbolizer!