SingleStore Interview Question

Tree based LC medium/hard question