determined time complexity of provlem 4