#3615
Longest Palindromic Path in Graph
hard · 22% accepted · 58 likes · top 2%
string · dynamic programming · bit manipulation · graph theory · bitmask
Description
You are given an integer n and an undirected graph with n nodes labeled from 0 to n - 1 and a 2D array edges, where edges[i] = [ui, vi] indicates an edge between nodes ui and vi.
You are also given a string label of length n, where label[i] is the character associated with node i.
You may start at any node and move to any adjacent node, visiting each node at most once.
Return the maximum possible length of a palindrome that can be formed by visiting a set of unique nodes along a valid path.
Solution