#3615

Longest Palindromic Path in Graph

international master · 2170 · lc hard +32 · 22% accepted · 58 likes · top 2%

Description

An undirected graph has n nodes (0-indexed) with edges [ui, vi]. Each node i has a character label label[i].

Starting at any node and moving to adjacent nodes (each visited at most once), form a sequence of character labels along the path.

Return the maximum length of a palindrome that can be formed from the labels along any such valid path.

Code

1
2
3