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)
296 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
Save
Save tree-striver-notes For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
296 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
Carousel Previous
Carousel Next
Download
Save
Save tree-striver-notes For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save tree-striver-notes For Later
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
Graph Hand Written Striver Notes
PDF
No ratings yet
Graph Hand Written Striver Notes
119 pages
Binary Seach Aditya Verma
PDF
100% (1)
Binary Seach Aditya Verma
26 pages
Data Structure by Pankaj Sir
PDF
No ratings yet
Data Structure by Pankaj Sir
58 pages
Striver Codes
PDF
No ratings yet
Striver Codes
199 pages
Striver Recursion Notes
PDF
No ratings yet
Striver Recursion Notes
52 pages
Striver Graph Notes
PDF
No ratings yet
Striver Graph Notes
37 pages
DSA Notes
PDF
No ratings yet
DSA Notes
84 pages
Google All Time Q
PDF
100% (1)
Google All Time Q
45 pages
Striver Recursion Notes
PDF
No ratings yet
Striver Recursion Notes
52 pages
DSA Revision Guide
PDF
No ratings yet
DSA Revision Guide
102 pages
00 Linked List Handwritten Notes
PDF
No ratings yet
00 Linked List Handwritten Notes
22 pages
Practice TCS NQT Advanced Coding - Questions Only
PDF
No ratings yet
Practice TCS NQT Advanced Coding - Questions Only
27 pages
DSA DSA: Questions For MAANG Interviews Questions For MAANG Interviews
PDF
No ratings yet
DSA DSA: Questions For MAANG Interviews Questions For MAANG Interviews
21 pages
Google Cracker Sheet
PDF
No ratings yet
Google Cracker Sheet
22 pages
DSA-251 by Parikh Jain
PDF
No ratings yet
DSA-251 by Parikh Jain
22 pages
LeetCode Solutions C++ All Boxed
PDF
0% (1)
LeetCode Solutions C++ All Boxed
2 pages
Juspay Interview Experience
PDF
No ratings yet
Juspay Interview Experience
4 pages
Trie Notes of Striver (TUF) Playlist
PDF
No ratings yet
Trie Notes of Striver (TUF) Playlist
24 pages
16 String Matching - Naive String Algorithm
PDF
100% (1)
16 String Matching - Naive String Algorithm
9 pages
Neetcode 150
PDF
No ratings yet
Neetcode 150
13 pages
Striver Graph
PDF
No ratings yet
Striver Graph
21 pages
CP RoadMap (Personal From BU)
PDF
No ratings yet
CP RoadMap (Personal From BU)
9 pages
DSA Patterns Sheet Kushal Vijay
PDF
No ratings yet
DSA Patterns Sheet Kushal Vijay
2 pages
Striver Graph Notes
PDF
0% (1)
Striver Graph Notes
37 pages
DSA Sheet Final - Google Sheets
PDF
No ratings yet
DSA Sheet Final - Google Sheets
9 pages
TCS CodeVita Exam All Details
PDF
No ratings yet
TCS CodeVita Exam All Details
12 pages
Technical Assessment Techie Codebuddy
PDF
100% (1)
Technical Assessment Techie Codebuddy
4 pages
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
Codebix: Live Class Syllabus
PDF
No ratings yet
Codebix: Live Class Syllabus
21 pages
Leetcode Preparation
PDF
No ratings yet
Leetcode Preparation
130 pages
Striver SDE Sheet
PDF
No ratings yet
Striver SDE Sheet
8 pages
TCS NQT Prep Sheet
PDF
No ratings yet
TCS NQT Prep Sheet
4 pages
Latest Data Structures
PDF
No ratings yet
Latest Data Structures
202 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
100 Most Asked Problems - LeetCode
PDF
No ratings yet
100 Most Asked Problems - LeetCode
8 pages
Linklist Love Babbar
PDF
No ratings yet
Linklist Love Babbar
43 pages
Microsoft Tree Questions
PDF
No ratings yet
Microsoft Tree Questions
29 pages
Blind 75
PDF
No ratings yet
Blind 75
4 pages
DSa Problems Cheatsheet
PDF
No ratings yet
DSa Problems Cheatsheet
27 pages
Software Prep Guide
PDF
No ratings yet
Software Prep Guide
74 pages
AlgoPrep's 151 Problems Sheet
PDF
No ratings yet
AlgoPrep's 151 Problems Sheet
6 pages
Competitive Programming
PDF
No ratings yet
Competitive Programming
7 pages
DSA Cheat Sheet
PDF
No ratings yet
DSA Cheat Sheet
4 pages
Walmart Labs - LeetCode
PDF
No ratings yet
Walmart Labs - LeetCode
4 pages
Paypal - LeetCode
PDF
100% (1)
Paypal - LeetCode
2 pages
Codeforces Tutorial
PDF
No ratings yet
Codeforces Tutorial
72 pages
Leetcode Questions - Public
PDF
No ratings yet
Leetcode Questions - Public
26 pages
Recurrence-Relations Time Complexity
PDF
No ratings yet
Recurrence-Relations Time Complexity
14 pages
Avl Trees
PDF
100% (1)
Avl Trees
25 pages
Complete Roadmaap
PDF
No ratings yet
Complete Roadmaap
2 pages
Interview Prep
PDF
No ratings yet
Interview Prep
10 pages
DSA Day 3
PDF
No ratings yet
DSA Day 3
12 pages
LeetCode Question Difficulty Distribution PDF
PDF
No ratings yet
LeetCode Question Difficulty Distribution PDF
4 pages
React Syllabus PDF
PDF
No ratings yet
React Syllabus PDF
6 pages
AA Trees PDF
PDF
No ratings yet
AA Trees PDF
55 pages
Sde Problems PDF
PDF
No ratings yet
Sde Problems PDF
7 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
Codility FAQ
PDF
No ratings yet
Codility FAQ
1 page
DSA Preparation Syllabus - PrepInsta Prime
PDF
No ratings yet
DSA Preparation Syllabus - PrepInsta Prime
1 page