Removed <algorithm> and increased readability of 2nd solution