public ListNode reverseKGroup(ListNode head, int k) {
        ListNode reverseHead = null, reverseTail = null;
        ListNode segHead = null, segTail = null;

        int count = 1;

        if (!canReach(head, k)) {
            return head;
        }

        while (head != null) {
            ListNode next = head.next;

            if (count == 1) {
                segHead = head;
                segTail = head;

                segTail.next = null;
            } else if (count <= k) {
                head.next = segHead;
                segHead = head;
            }
            if (count == k) {
                if (reverseHead == null) {
                    reverseHead = segHead;
                    reverseTail = segTail;
                } else {
                    reverseTail.next = segHead;
                    reverseTail = segTail;
                }

                if (next != null && !canReach(next, k)) {
                    reverseTail.next = next;
                    break;
                }

                count = 1;
            } else {
                count ++;
            }

            head = next;
        }

        return reverseHead;
    }