A log panel holds entries in a linked list, and each node's val is the entry's severity score. To make the quiet entries easy to skim, the panel moves every entry with a score lower than limit to the front.
Write splitBySeverity(head, limit) that reorders the nodes so all nodes with val < limit come before all nodes with val >= limit. Inside each of the two groups, keep the original order. Return the new head.
Input: head = [1,4,3,2,5,2], limit = 3 Output: [1,2,2,4,3,5]
1, 2, 2 are below 3 and keep their order; 4, 3, 5 follow in their order.
Input: head = [2,1], limit = 2 Output: [1,2]
Only 1 is below 2, so it moves in front of 2.
0 to 200 nodes.-100 <= node.val, limit <= 100Lists are written as arrays here, like [1, 2, 3]. Your function works with ListNode objects, each with val and next.
Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #228 Split Logs Around a Severity. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.