2872. Maximum Number of K-Divisible Components | leetcode daily challenge | shashcode30

preview_player
Показать описание
Problem Name:
2872. Maximum Number of K-Divisible Components

Problem Statement:
There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.

You are also given a 0-indexed integer array values of length n, where values[i] is the value associated with the ith node, and an integer k.

A valid split of the tree is obtained by removing any set of edges, possibly empty, from the tree such that the resulting components all have values that are divisible by k, where the value of a connected component is the sum of the values of its nodes.

Return the maximum number of components in any valid split.

Problem Link:

Solution Link:

Graph Playlist:

Java Plus DSA Placement Course Playlist:

Java Plus DSA Sheet:

Notes:

Telegram Link:

Ultimate Recursion Series Playlist:

Samsung Interview Experience:

Company Tags:
Facebook | Amazon | Microsoft | Netflix | Google | LinkedIn | Pega Systems | VMware | Adobe | Samsung

Timestamp:
0:00 - Introduction
Рекомендации по теме
Комментарии
Автор

As the year comes to a close, I want to take a moment to express my heartfelt gratitude to Shashcode for coming up with daily challenge videos and other DSA series which has helped me a lot in my interview preparation. Thank you for doing what you are doing 👏👏🎉

jyotiutb
Автор

like target is 150. Please do like and comment, if you have understood the explanation as well as code😄

shashwat_tiwari_st
Автор

Bhaiya apne daily challenge band kr diya, I am waiting daily for your videos

yash
Автор

Sir, you haven't uploaded todays leetcode daily challenge !!!!

nihalsingh
Автор

One Thing that can be done to handle large sum is to return sum%k (only the remainder).

Ajay-cvzs
Автор

where are you? why not uploading POTD leetcode?

bhushanambhore
Автор

I dont get the point of why there is need of comopnentCount to be an array of length 1 instead of simply being an integer?

bhushanambhore
Автор

sir can we use disjoint set in this question to group all those components whose sum is divisible by k ?

nishantrathore
Автор

Hello Sir, might be a silly question or maybe i didn't understand the problem but, is it possible that in the second example values[0] isn't divisible by given k=3 even after getting 0s from all subtrees. if yes, how is this approach handling that case.

karmaff
welcome to shbcf.ru