1609. Even Odd Tree🌳 || Amazon & Bloomberg interview question || Python 3 #dsa #code #amazon #google

preview_player
Показать описание
Intuition

MEDIUM SE THODA NICHE HAI

The problem requires checking if a given binary tree follows specific properties where even-indexed levels have nodes with odd values in increasing order and odd-indexed levels have nodes with even values in decreasing order. We'll use BFS traversal to traverse the tree level by level and check if these properties are satisfied.

Approach

1) Initialize a queue with the root of the tree and set the current level to 0.

2) While the queue is not empty:

•Pop nodes from the queue one by one.

•Check if the value of the node satisfies the conditions based on the current level.

•Enqueue the children of the node if they exist.
If the level is even, the node value should be odd and strictly increasing compared to the previous node value at this level.

•If the level is odd, the node value should be even and strictly decreasing compared to the previous node value at this level.

•If the conditions are not met, return False.

3) If the tree satisfies all the conditions, return True.

10 + Big Company asked for an interview

Plz support & Subscribe (for placement guidance)

#leetcode #problemoftheday #like #2024 #increseviews #batch #funcode #feb #code #dss
Рекомендации по теме
Комментарии
Автор

Sir please start the tutorial for basic python

LK_trollface
Автор

Please give shoutout to this channel plese

LK_trollface
welcome to shbcf.ru