6 kyu

Largest Radial Sum

59 of 478zeroxoneafour

Description:

The Codewars Council meets at a circular table with n seats. Depending on the day d of the month, d people will be chosen as leaders of the council. These d leaders are spaced equidistantly from each other on the table, like spokes on a wheel. The leaders are chosen based on which grouping of d equidistant people have the largest summed honor. The honor of the participants for that day in the Council is given in an array arr of length n. Return the combined honor of the d leaders of the Council.

Given conditions -

  • n % d == 0, ie. there will be no invalid cases. All groupings go fully around the circle.
  • 1 <= d <= 31, as you can't have 32 days in a month.
  • n > 0 because you can't have a Council of 0 people. (You also can't have a table with 0 open seats, then it's just a nightstand or something)
  • You can have negative honor on Codewars (but it is hard to do) and the solution may be negative.

Example -

[1, 2, 3, 4], 2 -> 6 because max(1+3, 2+4) == 6

[1, 5, 6, 3, 4, 2], 3 -> 11 because max(1+6+4, 5+3+2) == 11

[1, 1, 0], 1 -> 1 because max(1, 1, 0) == 1

Hint -

Something important to note is that you (usually) don't have to evaluate every sum in the array, as after n/d repetitions the sums loop over on themselves.

Arrays
Algorithms

Stats:

CreatedAug 29, 2023
PublishedAug 29, 2023
Warriors Trained1351
Total Skips38
Total Code Submissions3243
Total Times Completed478
Java Completions59
C++ Completions68
Python Completions156
TypeScript Completions32
Haskell Completions13
JavaScript Completions173
Scala Completions6
Rust Completions20
PHP Completions11
Total Stars22
% of votes with a positive feedback rating91% of 80
Total "Very Satisfied" Votes68
Total "Somewhat Satisfied" Votes10
Total "Not Satisfied" Votes2
Total Rank Assessments22
Average Assessed Rank
7 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • zeroxoneafour Avatar
  • JohanWiltink Avatar
  • eurydice5717 Avatar
  • Wisdou Avatar
  • akar-0 Avatar
  • mauro-1 Avatar
  • cwps Avatar
  • KayleighWasTaken Avatar
  • HartlIKS Avatar
Ad