I need to create a UI as in the diagram, which will change its layout depending on the class passed to its elements (2 views).
the first layout looks like two columns, in the first column 2 divs (a and b) one on top another without a gap and the third div (c) in the second column aligned to the top.
the second layout - all 3 divs are in one column but the div from the second column(c) enters in between them (a and b)
I tried to use grid css and 2 columns for the first layout (grid-template-columns: auto auto) to turn it to one column in the 2nd view (grid-template-columns: auto) but the problem is that C block is longer than A so the grid row lengthens according to the longest div so there is a big gap between A and B. Any ideas preferably using flex or grid?

.a {
width: 50px;
height:30px;
background: pink;
}
.b {
width: 50px;
height:80px;
background: green;
}
.c {
width: 50px;
height:80px;
background: red;
}
.cont {
display: grid;
grid-template-columns: auto auto;
width: 120px;
}
<div class="cont">
<div class="a">A
</div>
<div class="c">C
</div>
<div class="b">B
</div>
</div>