← All problemsSign in

Niceness of a tree

In a tree, a node having degree ≥ 3 is said to be a nice node. For tree T, it's niceness is defined by the pseudo code given below. int niceness(Tree T): ans = 0; while (T is not empty): Identify all the nice nodes. Remove all nodes of T which have a path to a leaf not passing through any nice node. ans++; return ans; e.g. niceness of the below given tree is 2. In the first iteration of

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