Yes, this is possible. You would set the A record in DNS for example.com to resolve to the IP address of company A, and create another A record for sub.example.com with the IP address for company B.

Only top voted, non community-wiki answers of a minimum length are eligible