Ad
  • Custom User Avatar

    Hi @Kippe and welcome to Codewars!

    You are allowed to pick a contiguous subarray of any length not just length = 4.

    So in the array you are asking about it turns out that the answer is the entire array sums up to 155 which is the maximum possible.

    Meanwhile, in the array [-1,-1,-2,100,230,-5,-7] the answer would be the subarray [100,230] which produces a sum of 330 which is the maximum possible, as for example including [-2,100,230,-5] would be less than 330 etc.

  • Custom User Avatar

    Hi,

    i thought i understand, but how can
    ([7, 4, 11, -11, 39, 36, 10, -6, 37, -10, -32, 44, -26, -34, 43, 43]), 155)
    sum up to 155? I dont see a substring of length 4 in this that could return 155.

  • Custom User Avatar

    Hi @Y0z64 and welcome to Codewars! Congratulations on solving, but please don't post spoilers to kata in the Discourse - the goal is for people to solve on their own.

    If you do want to discuss specific implementations you should use the Spoiler flag; this makes your comment invisible to people who have not yet solved the kata.

  • Custom User Avatar

    No .format() solution because im way to lazy to understand how that works.
    Still, this works

  • Custom User Avatar

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

  • Custom User Avatar

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

  • Custom User Avatar

    Please use spoiler flag next time.

  • Custom User Avatar

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

  • Custom User Avatar

    I made a whole function to separate the number from each word and added it to the same list to make a 2d table, afther that i used list comprehension to sort the words and at the same time eliminate the number, all of this last part inside a " ".join(...) to transform the array again into a string.

    The problem is that I realized way to late that by sorting again each word the number is separated and put in the first position of the array (so word[0]) so the whole function to separate the number is unnecesary. Plus this can be done inside the sorted() by using "key = lambda x:sorted(x)" efectivly sorting two times in a row and automatically sorting each word into place.

    Even though big part of my code is unnecessary im proud i could solve this problem by myself and without the use of external libraries.

  • Custom User Avatar

    I just realized you dont need to turn it into an array becuase you can use sorted() on strings so just do sorted(srt(num),reverse=True
    Also there is no need to create a variable to return and can just write the "".join(...) directly into the return