O(sqrt(n)) space complexity and O(n) time complexity solution:
It is inspired by the fact that sqrt(n) * sqrt(n) = n and the "reverse words in a sentence" problem

void reverse(ListNode* begin) { int n = 0; auto ptr = begin; while (ptr) { ++n; ptr = ptr -> next; } int k = ceil(sqrt(n)); vector<ListNode*> tmp1(k, NULL), tmp2(k, NULL); int i = 0; ptr = begin; while (ptr) { tmp1[i] = ptr; ++i; for (int j = 0; j < k && ptr; ++j, ptr = ptr -> next) ; } i = tmp1.size() - 1; while (i >= 0 && tmp1[i] == NULL) --i; if (i < 0) return; while (i >= 0) { auto p = tmp1[i]; for (int j = 0; j < k && p; ++j, p = p -> next) tmp2[j] = p; for (int j = k - 1; j >= 0; --j) { if (tmp2[j]) { cout << tmp2[j] -> val << " "; } } for (int j = 0; j < k; ++j) { tmp2[j] = NULL; } --i; } cout << endl; }