← All problemsSign in

3939. Count Non Adjacent Subsets in a Rooted Tree

LeetCodeArrayDynamic ProgrammingTreeDepth-First SearchOpen on judge ↗

You are given a rooted tree with n nodes labeled from 0 to n - 1, represented by an integer array parent of length n, where: - parent[0] = -1 (node 0 is the root). - For each 1 <= i < n, parent[i] is the parent of node i (0 <= parent[i] < i). You are also given an integer array nums of length n, where nums[i] is the value of node i, and an integer k. A non-empty subset of nodes is called valid

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start