[Community Puzzle] Container Terminal

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

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!

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

Itās the ā¦ ooh, wait, thatās not where iām wrong, itās was the line before that one

Sorry !

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

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

1 Like

Thanks a lot Yatech, youāve explained it perfectly now.

2 Likes