Solution for the first part of quick sort problem