I am going to show you two ways to solve this problem, one method just uses a diagram and the other uses addition and multiplication of fractions.
I drew a rectangle to represent a whole stock and coloured Sam's half orange and Mary's half green.
Sam then divided his half sock into three equal parts and sold two of them to Mary.
If Mary divides her original half stock in three as Sam did you can easily see how much she now owns.
The stock is divided into six equal sized pieces and Mary owns five of them so she owns 5/6 of a stock.
Sam owns 1/2 a stock and he sells 2/3 of his stock to Mary. 2/3 of 1/2 is 2/3 × 1/2 = 1/3. Mary already owned 1/2 a stock so now she owns
1/2 + 1/3 = 3/6 + 2/6 = 5/6 of a stock.