[Community Puzzle] Bin packing

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @java_coffee_cup,validated by @PPS and @cedricdd.
If you have any issues, feel free to ping them.

Hi everyone,

I created a solution in C# that can find all combinations of a given sum in an array, and I use it recursively to test in a bruteforce-like manner. It’s very generic and works well. I pass 100% of regular Test cases “Samples” and “NP-Easy/Medium/Hard”. When I submit the Solution, I don’t pass the “Samples Validator”, but I pass all "“NP-Easy/Medium/Hard Validators”.

This is very strange, as I clearly don’t test for any particular scenarios and my solution is so generic so it can pass everything but one validator? Has anyone faced something similar? Don’t want to post my whole Source code but I can of course… How should I proceed?

There was a trailing space on one of the lines in that validator. I’ve removed that, see if that fixes your solution.

It absolutely did, thank you very much for the fast reaction! :star_struck:

Thank you making the fix.

Have no idea how a trailing space can get into there without causing my checker solution to fail… :thinking: :question:

It was in the input for one of the tests. The java scanner input will just ignore extra whitespace, but in c# it’s easier to read the full line and split. The c# split function returns [“1”,“2”,“”] for "1 2 " and trying to convert the empty string to an int (assuming the user just converts the entire array as there shouldn’t be anything else) gives an error.

2 Likes

I pass the two first tests and not the two others, but it is not a timeout, I find a wrong answer.
For example, NP Hard, my answer for the 2nd line is “no” instead of “yes”.

Is there a trap in these tests that is not in the two first ?

I had similar issues at first. Depending on your algorithm, I put this into the Spoiler region, don’t open if you don’t want hints.

Spoiler

Often you take the first working combination, then proceed with the next bin, take the first working in the remaining set etc. and you might end up having a mismatch at the end so you return “no”. What you need to do is consider other combinations, too. Don’t reject prematurely. Hope it helps.

1 Like

That’s true, I do that … thank you, I’ll try to fix it.

I see. In the future, will add a section of input format checking code as a routine.

1 Like