An icon editor has a "single-stroke" check for line icons. The icon has points numbered 0 to n - 1, and lines[i] = [a, b] is a straight line between points a and b.
Write oneStroke(n, lines) that returns true if the icon can be drawn without lifting the pen and without drawing any line twice, and false otherwise. Points with no lines don't matter. An icon with no lines counts as drawable.
Input: n = 4, lines = [[0,1],[1,2],[2,3],[3,0],[0,2]] Output: true
A square with one diagonal: points 0 and 2 touch 3 lines each and the others touch 2, so start at 0 and finish at 2.
Input: n = 4, lines = [[0,1],[0,2],[0,3]] Output: false
Four points touch an odd number of lines. A single stroke allows at most two.
1 <= n <= 100000 <= lines.length <= 500000 <= a, b < n, a !== bRun 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 #479 Draw the Icon in One Stroke. 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.