A music app has a "mirror mix" badge for playlists that read the same forwards and backwards, such as track ids 4, 9, 9, 4. The playlist is a linked list of track ids.
Write isMirrorMix(head) that returns true if the values read the same in both directions, otherwise false. An empty playlist counts as a mirror mix. Try to use only O(1) extra space.
Input: head = [1,2,2,1] Output: true
Read backwards it is still 1, 2, 2, 1.
Input: head = [1,2] Output: false
Backwards it is 2, 1, which is different.
0 to 10^5 nodes.0 <= node.val <= 9Lists 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 #232 Symmetric Playlist Check. 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.