Skip to content

Day 344 #686

Closed
Closed

Description

@vaskoz

Good morning! Here's your coding interview problem for today.

This problem was asked by Adobe.

You are given a tree with an even number of nodes. Consider each connection between a parent and child node to be an "edge". You would like to remove some of these edges, such that the disconnected subtrees that remain each have an even number of nodes.

For example, suppose your input was the following tree:

   1
  / \ 
 2   3
    / \ 
   4   5
 / | \
6  7  8

In this case, removing the edge (3, 4) satisfies our requirement.

Write a function that returns the maximum number of edges you can remove while still satisfying this requirement.

Activity

  1. self-assigned this
    on Aug 1, 2019
  2. vaskoz commented on Oct 19, 2019

    @vaskoz
    OwnerAuthor

    The maximum number of edges for this test cases is actually 2.

    Removing (3, 4) and (1, 3) resulting in 3 separate subtrees of even nodes.

    3 Subtrees:

    • (1, 2) - 2 nodes
    • (3, 5) - 2 nodes
    • (4, 6, 7, 8) - 4 nodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions