Beta
Layout ordered sections in columns
18 of 21mweiss
Loading description...
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
random tests?
Nice, this is a fairly challenging kata. I enjoyed it.
My only concern is that the returned array is a little odd. I think it would make sense to include the initial
0
, or return an array of arrays of section lengths. Either seems more natural, but it's not enough to ruin the kata.Also, I don't know if my solution is truly a valid one, but it passed all the tests. :-)
I like your solution! It's way more efficient than the brute force one, especially when there's a lot of columns. I'm not sure if there's a test case that breaks it.
I agree it's more straight forward to include the initial 0. I've modified the kata so that the output is an array of starting indexes including the initial 0.
Cool, I'll update my solutions... :-D
An example that breaks my solution would be
[5,5,3,3,1,1,2,3,4]
at 3 columns. It should render to[[5,5],[3,3,1,1],[2,3,4]]
for the optimal case (col heights of[10,8,9]
), but ends up becoming[[5,5],[3,3],[1,1,2,3,4]]
(heights of[10,6,11]
).I'm not sure the solution without a major change to how it works. I might be able to add in a loop that looks for any 2 columns more than 2 units apart, and attempt to even them out.
Ah, that's true! I've added that test case. I'm not 100% sure how you'd even them out to be guaranteed the optimal solution, but I look forward to a cool solution.
Oof, I thought I had a solution, but then ran into a real pickle with this input:
[5,5,1,1,1,5,3,2,1,1,2,3,4]
at4
columns, which should result in:[0,2,6,10]
for column heights of[10,8,7,9]
.However, because of where the 3rd
5
is, I keep getting stuck at[0,1,5,10]
, which has heights of[5,8,12,9]
.I'm not sure, at this point, of an easy, non-brute force method for solving it. I'll keep thinking about it.
I just realized that the correct solution to that would actually be
[0,2,6,11]
, if you assume left-weighted priority.I have a much better solution I'll be posting in a minute.Scratch that, no such luck on the better solution.