#3841

Palindromic Path Queries in a Tree

master · 1865 · lc hard +32 · 34.7% accepted · 52 likes · top 12%

Description

An undirected tree with n nodes (labeled 0 to n - 1) is given via edges, and each node i holds character s[i]. You receive a list of string queries; each is one of:

- "update ui c": set s[ui] = c.

- "query ui vi": check whether the characters along the unique path from ui to vi (inclusive) can be rearranged into a palindrome.

Return a boolean array answer where answer[j] is true if the jth "query" operation can form a palindrome, false otherwise.

Code

1
2
3