Problem definition:
I have product under below category:
Beauty --> Sun --> my-some-product-name.
where 'Beauty' is root category and 'Sun' is the subcategory of 'Beauty'.
Currently, I am trying to get root category id and subcategory id of product separately.
How to get above data in Magento 2.2.6 product ID?