Pinterest interview question

Implement bagging with the given functions