A product carousel keeps its cards in a linked list and should open centered on the middle card. The list doesn't store its length.
Write middleCard(head) that returns the middle node (the returned list is the middle card and every card after it). When the list has an even number of cards there are two middle cards: return the second one.
Input: head = [1,2,3,4,5] Output: [3,4,5]
The middle of five cards is the third, 3.
Input: head = [1,2,3,4,5,6] Output: [4,5,6]
3 and 4 are both in the middle, so return the second, 4.
1 to 100 nodes.1 <= node.val <= 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 #230 Middle of the Carousel. 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.