- Linked List, Linked Lists, Mathematical, partition

Partition a Linked List into K continuous groups with difference in their sizes at most 1

  #include using namespace std;  struct ListNode {    int val;    struct ListNode* next;};  void push(ListNode** head_ref,          int node_val){        ListNode* new_node = new ListNode();          new_node->val = node_val;          new_node->next = (*head_ref);          (*head_ref) = new_node;}  void splitListInParts(ListNode* head,                      int K){        vector ans;          if (!head) {                  while (K–)            ans.push_back(NULL);    }              int N = 0;              ListNode* p = head;          while (p) {                  p = p->next;                  N++;    }      int len = N / K;    int rem = N % K;      p = head;          while (K > 0 && p) {                          int x = len;                  ListNode* curr_head = p;                  ListNode* last = p;                  if (rem > 0) {                          p = p->next;                          rem–;        }                  while (x–) {                          if (last == p)                p = p->next;                          else {                                                                  last->next = p;                                  last = p;                                  p = p->next;            }        }                  last->next = NULL;                          ans.push_back(curr_head);                  K–;    }          while (K > 0) {                  ans.push_back(NULL);                  K–;    }          cout