[Community Puzzle] Container Terminal

https://www.codingame.com/training/easy/container-terminal

Send your feedback or ask for help here!

Created by @java_coffee_cup,validated by @C2H5OH,@TBali and @LaurentValade.
If you have any issues, feel free to ping them.

Hey guys ,
I know I need to take in the account the order in which the trucks are coming so sorting the string will not help . I figured that by comparing each value with the next one and stacking it if it`s a smaller value or starting a new stack if it is bigger would help but in cases like CBACBACBACBA I am stuck . Can you point me in a direction?

It can be done by comparing value of the incoming container with the current ‘top’ ones on the stacks like you said

CBACBACBA could be stacked
CBA
CBA
CBA

But it could also be stacked this way:
After first CBA
A
B
C

After second CBA
A
A
BB
CC

After third CBA
A
A
AB
BB
CCC

6 Likes

Yes , I figured that . What I meant was that I can`t figure out when to stack the smaller value or to wait because somewhere along the string is a better option. Like in the CBACBACAB test case the right answer is 3 ( I suppose they mean AAA BBB CCC).
But when I compare B with C , B is smaller so I could stack how should I know at that point that a C will come around .

You don’t have to know if C will come around. Look at my example above - B is stacked on C, but the final result would still be 3 stacks.

1 Like

Hi guys! Frankly, I have difficulties understanding the part “In the real world there is a maximum height limit for each stack of containers. In this puzzle we assume there is no such limit.”. So what prevents me from, say, in the case of “CODINGAME” to sort the containers alphabetically and putting them in one stack?

Containers are coming in like a stream. When one comes in, you have to immediately decide where to put it down. Once put down, it will not be moved again until it is time for loading to ships.

Finding an extra storage place for sorting and doing extra moving jobs are inefficient.

1 Like

Ah, ok, thanks for the clarification! :slight_smile:

Wow thanks I was focusing only on the [[CCC],[BBB],[AAA]] so I made it extremely complicated. Finally it was easy thanks to you !

1 Like

That’s supposed to be an easy puzzle, but I can’t figured out how i’m supposed to do the last tests.
The first string which i’m getting wrong is similar to that one (i removed a couple of useless letter in there)
JJBYHJRZ

I’m getting 5 columns :
JJJ, B, YH, R, Z

If i was to do it manually, i would not do much better : JJB, YH, J, R, Z

What am i missing here? ?_?

For a string JJBYHJRZ the answer would indeed be 5.
Which test exactly are you getting wrong?

1 Like

:face_with_monocle:
It’s the … ooh, wait, that’s not where i’m wrong, it’s was the line before that one :man_facepalming:

Sorry ! :smiley:

On the third test how would MIWEWESTEWEMEMIMEW be split into only four stacks?

one of the possible solutions (each row is a stack):

[W, W]
[T, M]
[M, I, E, E, E, E, E, E]
[W, W, S, M, M, I]

Thank you!

I think I’m probably dumb because your hint seems to be helpful, but after staring at it for an hour, I still don’t understand the logic.

1 Like

I’m not sure how to explain it better so here’s a visualization :slight_smile:

9 Likes

In other words: put it where it hurts the less.

Thanks you ! I was like Aathish, because I was reading your example lines by lines and not columns by columns…
Nice explanation :slight_smile:

1 Like

Thanks a lot Yatech, you’ve explained it perfectly now.

2 Likes