Yes, it's possible - provided they are the same battery chemistry and the total Ah for each group in series is consistent.
For example, the sum of each group in series should be the same. If one is 300Ah, the others should add up to 300Ah too.
For people making packs of 18650 batteries, programs like rePackr can help build your pack once you have checked the capacity.
(e.g. Tesla with Leaf batteries provided total Ah of Leaf same as Tesla in your battery pack)