Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
138 views
46 pages
Tree Striver Notes
data structures and algorithms
Uploaded by
ballistic.code
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Download now
Download
Save tree-striver-notes For Later
Download
Save
Save tree-striver-notes For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
138 views
46 pages
Tree Striver Notes
data structures and algorithms
Uploaded by
ballistic.code
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF, TXT or read online on Scribd
Download now
Download
Save tree-striver-notes For Later
Carousel Previous
Carousel Next
Download
Save
Save tree-striver-notes For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 46
Search
Fullscreen
return -1 if it is not balanced and return height of the tree is it is balanced
// Function to calculate the height of
// the tree and update the diameter
int height(Node* node, int& diameter) {
if (!node) {
return 0;
}
int lh = height(node->left, diameter);
int rh = height(node->right, diameter);
diameter = max(diameter, lh + rh);
return 1 + max(lh, rh);
}
};
class Solution {
public:
vector<vector<int>> verticalTraversal(TreeNode* root) {
// vertical =x and level=y
//[x][y]=set of all values at current vertical,level;
map<int,map<int,multiset<int>>> nodes;
//node , pair<vertical,level>
// vertical =x and level=y
queue<pair<TreeNode*,pair<int,int>>> q;
q.push({root,{0,0}});
while(!q.empty())
{
TreeNode* node=q.front().first;
int x=q.front().second.first;
int y=q.front().second.second;
q.pop();
nodes[x][y].insert(node->val);
if(node->left)
q.push({node->left,{x-1,y+1}});
if(node->right)
q.push({node->right,{x+1,y+1}});
}
vector<vector<int>> ans;
for(auto p:nodes)
{
vector<int> col;
for(auto q:p.second)
{
col.insert(col.end(),q.second.begin(),q.second.end());
}
ans.push_back(col);
}
return ans;
then its full binary tree
You might also like
System Design Interview Vol2
PDF
100% (3)
System Design Interview Vol2
427 pages
Grokking The Advanced System Design Interview
PDF
91% (11)
Grokking The Advanced System Design Interview
397 pages
Grokking The System Design Interview PDF
PDF
93% (46)
Grokking The System Design Interview PDF
196 pages
DSA Pattern Wise Product - Parikh Jain
PDF
No ratings yet
DSA Pattern Wise Product - Parikh Jain
37 pages
Grokking The Java Developer Interview - More Than 200 Questions To Crack The Java, Spring
PDF
100% (2)
Grokking The Java Developer Interview - More Than 200 Questions To Crack The Java, Spring
330 pages
Complete Data Structures and Algorithms Guide 30DaysCoding
PDF
100% (1)
Complete Data Structures and Algorithms Guide 30DaysCoding
96 pages
800 Data Science Questions
PDF
100% (2)
800 Data Science Questions
258 pages
System Design Interview - An Insider's Guide
PDF
90% (10)
System Design Interview - An Insider's Guide
103 pages
Alex Xu System Design
PDF
100% (3)
Alex Xu System Design
16 pages
Top FAANG Interview Questions From LeetCode
PDF
No ratings yet
Top FAANG Interview Questions From LeetCode
15 pages
Microsoft Tree Questions
PDF
No ratings yet
Microsoft Tree Questions
29 pages
Interview Prep
PDF
No ratings yet
Interview Prep
10 pages
Coding Interview-Leetcode
PDF
83% (6)
Coding Interview-Leetcode
181 pages
Practical Projects
PDF
100% (29)
Practical Projects
478 pages
Engineering Manager Interview Questions
PDF
No ratings yet
Engineering Manager Interview Questions
27 pages
Google Cracker Sheet
PDF
No ratings yet
Google Cracker Sheet
22 pages
Striver Graph
PDF
No ratings yet
Striver Graph
21 pages
Competitive Programming in Python 128 Algorithms To Develop Your Coding Skills
PDF
100% (8)
Competitive Programming in Python 128 Algorithms To Develop Your Coding Skills
267 pages
Leetcode Preparation
PDF
No ratings yet
Leetcode Preparation
130 pages
System Design Primer
PDF
No ratings yet
System Design Primer
80 pages
100 Days Preparation Strategy To Crack Product Based Companies
PDF
50% (2)
100 Days Preparation Strategy To Crack Product Based Companies
33 pages
Solved Questions Competitive Programming
PDF
No ratings yet
Solved Questions Competitive Programming
119 pages
Python Notes For Professionals
PDF
100% (17)
Python Notes For Professionals
814 pages
Amazon Interview Questions - CareerCup
PDF
25% (4)
Amazon Interview Questions - CareerCup
4 pages
Educative Top 10 System Design
PDF
No ratings yet
Educative Top 10 System Design
19 pages
Striver Graph Notes
PDF
No ratings yet
Striver Graph Notes
37 pages
DSA Patterns Sheet Kushal Vijay
PDF
No ratings yet
DSA Patterns Sheet Kushal Vijay
2 pages
Striver Codes
PDF
No ratings yet
Striver Codes
199 pages
Trie Notes of Striver (TUF) Playlist
PDF
No ratings yet
Trie Notes of Striver (TUF) Playlist
24 pages
Striver Recursion Notes
PDF
No ratings yet
Striver Recursion Notes
52 pages
Striver Graph Notes
PDF
0% (1)
Striver Graph Notes
37 pages
Striver SDE Sheet
PDF
No ratings yet
Striver SDE Sheet
8 pages
Graph Hand Written Striver Notes
PDF
No ratings yet
Graph Hand Written Striver Notes
119 pages
Master Competitive Programming
PDF
No ratings yet
Master Competitive Programming
16 pages
DSA Sheet Final - Google Sheets
PDF
No ratings yet
DSA Sheet Final - Google Sheets
9 pages
Codeforces Tutorial
PDF
No ratings yet
Codeforces Tutorial
72 pages
Competitive Programming
PDF
No ratings yet
Competitive Programming
7 pages
Striver's CP List (Solely For Preparing For Coding Rounds of Top Prod Based Companies and To Do Well in Coding Sites and Competitions)
PDF
No ratings yet
Striver's CP List (Solely For Preparing For Coding Rounds of Top Prod Based Companies and To Do Well in Coding Sites and Competitions)
30 pages
Binary Seach Aditya Verma
PDF
100% (1)
Binary Seach Aditya Verma
26 pages
Sasken Sample Technical Placement Paper Level1
PDF
No ratings yet
Sasken Sample Technical Placement Paper Level1
6 pages
Placement Preparation Material
PDF
No ratings yet
Placement Preparation Material
2 pages
Sde Problems
PDF
No ratings yet
Sde Problems
8 pages
DSA-251 by Parikh Jain
PDF
No ratings yet
DSA-251 by Parikh Jain
22 pages
Baidu - LeetCode
PDF
No ratings yet
Baidu - LeetCode
2 pages
Walmart Labs - LeetCode
PDF
No ratings yet
Walmart Labs - LeetCode
4 pages
Data Structure & Algorithm: Fundamental of DSA
PDF
No ratings yet
Data Structure & Algorithm: Fundamental of DSA
30 pages
Paypal - LeetCode
PDF
100% (1)
Paypal - LeetCode
2 pages
C++, C, OPP Questions in Interview
PDF
No ratings yet
C++, C, OPP Questions in Interview
22 pages
Capgemini Interview
PDF
No ratings yet
Capgemini Interview
13 pages
DSA Revision Guide
PDF
No ratings yet
DSA Revision Guide
102 pages
Leetcode 75 Questions (NeetCode On Yt) - Google Sheets
PDF
No ratings yet
Leetcode 75 Questions (NeetCode On Yt) - Google Sheets
1 page
CP RoadMap (Personal From BU)
PDF
No ratings yet
CP RoadMap (Personal From BU)
9 pages
TCS NQT Prep Sheet
PDF
No ratings yet
TCS NQT Prep Sheet
4 pages
Competitive Programming Part-02
PDF
No ratings yet
Competitive Programming Part-02
74 pages
DSA Preparation Syllabus - PrepInsta Prime
PDF
No ratings yet
DSA Preparation Syllabus - PrepInsta Prime
1 page
Capgemini Cloud Fundamentals
PDF
No ratings yet
Capgemini Cloud Fundamentals
11 pages
LeetCode Solutions C++ All Boxed
PDF
No ratings yet
LeetCode Solutions C++ All Boxed
2 pages
Codility FAQ
PDF
No ratings yet
Codility FAQ
1 page
COA (Week 1 To Week 12 Detailed Solution)
PDF
No ratings yet
COA (Week 1 To Week 12 Detailed Solution)
53 pages
Algo Zenith
PDF
No ratings yet
Algo Zenith
28 pages
TCS NQT 4
PDF
No ratings yet
TCS NQT 4
23 pages
Top Data Structure Interview Questions and Answers Are Below
PDF
No ratings yet
Top Data Structure Interview Questions and Answers Are Below
17 pages
Must Know Quantitative Aptitude Concepts For TCS Ninja: Faceprep - in
PDF
No ratings yet
Must Know Quantitative Aptitude Concepts For TCS Ninja: Faceprep - in
21 pages
AVL Tree
PDF
No ratings yet
AVL Tree
34 pages
Practice TCS NQT Advanced Coding - Questions Only
PDF
No ratings yet
Practice TCS NQT Advanced Coding - Questions Only
27 pages
2011 Sasken Placement Paper
PDF
No ratings yet
2011 Sasken Placement Paper
9 pages
Linklist Love Babbar
PDF
No ratings yet
Linklist Love Babbar
43 pages
Aptitude Training Notes For Placement Preparation
PDF
No ratings yet
Aptitude Training Notes For Placement Preparation
80 pages
Complete Roadmaap
PDF
No ratings yet
Complete Roadmaap
2 pages
Interview Prep
PDF
No ratings yet
Interview Prep
10 pages
Technical Assessment Techie Codebuddy
PDF
100% (1)
Technical Assessment Techie Codebuddy
4 pages
Low Level Design
PDF
100% (1)
Low Level Design
103 pages
Study-Materials CSE 6th Cryptography-Network-Security S.-Dalai
PDF
No ratings yet
Study-Materials CSE 6th Cryptography-Network-Security S.-Dalai
63 pages
CP RoadMap(Personal from BU)
PDF
No ratings yet
CP RoadMap(Personal from BU)
9 pages
DSA DAY 6 - Graphs
PDF
67% (3)
DSA DAY 6 - Graphs
45 pages
Striver's CP List (Solely For Preparing For Coding Rounds of Top Prod Based Companies)
PDF
100% (1)
Striver's CP List (Solely For Preparing For Coding Rounds of Top Prod Based Companies)
7 pages
DSa Problems Cheatsheet
PDF
No ratings yet
DSa Problems Cheatsheet
27 pages
DSA Day 3
PDF
No ratings yet
DSA Day 3
12 pages
AP 2.1 - Removed
PDF
No ratings yet
AP 2.1 - Removed
4 pages
Cracking System Design Interview Like A Pro - A 10 Day
PDF
50% (10)
Cracking System Design Interview Like A Pro - A 10 Day
199 pages
Coderbyte Ebook
PDF
100% (2)
Coderbyte Ebook
58 pages
Coding Patterns
PDF
100% (1)
Coding Patterns
26 pages
Leet - Code Solution
PDF
100% (1)
Leet - Code Solution
630 pages
Leetcode Hard1
PDF
100% (6)
Leetcode Hard1
1,364 pages
Google Interview Preparation
PDF
100% (2)
Google Interview Preparation
3 pages
Ebook - Cracking The System Design Interview Course
PDF
100% (1)
Ebook - Cracking The System Design Interview Course
91 pages
An Insiders Guide To Ace System Design in - Maurice Jayson
PDF
100% (2)
An Insiders Guide To Ace System Design in - Maurice Jayson
60 pages
Hands On Machine Learning With Python Concepts and Applications For Beginners - John Anderson 2018
PDF
91% (11)
Hands On Machine Learning With Python Concepts and Applications For Beginners - John Anderson 2018
166 pages
Full Course of Machine Learning
PDF
100% (16)
Full Course of Machine Learning
660 pages