Leetcode POTD
Approach\nFind the size of LinkedList, say len \n\nint len = 0;\nListNode* cur = head;\nwhile(cur != NULL){\n    ++len;\n    cur = cur->next;\n}\n\nDo simple ma
# Approach\nFind the size of LinkedList, say ```len``` \n```\nint len = 0;\nListNode* cur = head;\nwhile(cur != NULL){\n    ++len;\n    cur = cur->next;\n}\n```\nDo simple math to divide ```len``` to k part. \nEach part will contain ```len / k``` elements and first ```len % k``` will contain *one* extra element.\n\n# Complexity\n- Time complexity: $$O(n)$$\n    ```O(n + k*(len/k)) -> O(n)```\n\n- Space complexity: $$O(n)$$ \n    ```To store the answer```\n\n# Code\n```\nclass Solution {\npublic:\n    vector<ListNode*> splitListToParts(ListNode* head, int k) {\n        int len = 0;\n        ListNode* cur = head;\n        while(cur != NULL){\n            ++len;\n            cur = cur->next;\n        }\n        vector<ListNode*> res(k,NULL);\n        // each will contain len/k element\n        // first len%k will contain one extra element\n        int sz = len/k;\n        int rem = len%k;\n\n        ListNode* curr = head;\n        ListNode* prev = NULL;\n        for(int i=0;i<k;i++){\n            res[i] = curr;\n            for(int j = 0;j < sz; j++){\n                prev = curr;\n                curr = curr->next;\n            }\n            if(rem > 0){\n                if(curr != NULL){\n                    prev = curr;\n                    curr = curr->next;\n                    --rem;\n                }\n            }\n            // disconnect the curr and mark new head as prev->next\n            if(prev != NULL){\n                head = curr;\n                prev->next = NULL;\n            }\n        }\n        return res;\n    }\n};\n```
['Linked List', 'C++']