5 kyu

Stable Weight Arrangement

42 of 85docgunthrop

Description:

Here is a simple task. Take an array/tuple of unique positive integers, and two additional positive integers. Here's an example below:

const arr = [3,5,7,1,6,8,2,4];
const n = 3; // span length
const q = 13; // weight threshold
arr = (3,5,7,1,6,8,2,4)
n = 3 # span length
q = 13 # weight threshold
var arr = []int{3,5,7,1,6,8,2,4}
var n int = 3 // span length
var q int = 13 // weight threshold

Try to re-arrange arr so that the sum of any n consecutive values does not exceed q.

solver(arr,n,q); // one possible solution: [4,7,1,5,6,2,3,8]
solver(arr,n,q) ## one possible solution: (4,7,1,5,6,2,3,8)
Solver(arr,n,q) // one possible solution: {4,7,1,5,6,2,3,8}

Did you succeed? Great! Now teach a computer to do it.

Technical Details

  • All test inputs will be valid
  • All test cases will have 0 or more possible solutions
  • If a test case has no solution, return an empty array/tuple. Otherwise, return a valid solution
  • Test constraints:
    • 2 <= n <= 6
    • 4 <= arr length < 12
    • n < arr length
    • Every value in arr will be less than q
    • 11 fixed tests, 25 random tests
  • In JavaScript, module and require are disabled
  • For JavaScript, use Node 10+
  • For Python, use Python 3.6+

If you enjoyed this kata, be sure to check out my other katas

Arrays
Algorithms

Similar Kata:

Stats:

CreatedSep 3, 2019
PublishedSep 4, 2019
Warriors Trained734
Total Skips60
Total Code Submissions709
Total Times Completed85
Python Completions42
JavaScript Completions28
Go Completions22
Total Stars29
% of votes with a positive feedback rating94% of 33
Total "Very Satisfied" Votes29
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes0
Total Rank Assessments3
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • docgunthrop Avatar
  • SQSCWQ Avatar
Ad