For AVL trees, how do we know if a RL or a LR rotation is needed? Suppose I am trying to construct a simple AVL tree:



Upon inserting 'B' the tree becomes imbalanced. How do I exactly know that I need a LR or RL rotation without making any guesses?

From what I heard is that if you insert at right side of tree and it becomes imbalanced then you need a LR rotation and vice-versa. I want to make sure that it is true.
In this case the tree is right-left unbalanced. That's because when you insert $B$ it causes the root node to become unbalanced. You can tell its right-left unbalanced from the path that goes from the newly inserted node to the root node i.e. $B$ is the right child of $A$ and $A$ is the left child of $C$. Therefore, it needs a left-right rotation.