0% found this document useful (0 votes)
10 views

Trees5 Adv April

Uploaded by

Ashish Soni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Trees5 Adv April

Uploaded by

Ashish Soni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

xfactor

Two pointers Hashing


String pattern matching
LL Stacks Queues Trees

Industry Expert Conversation

Q Invert the given BinaryTree


I inverted bee
y

z 13 s sh f ly
I
Is 16 l
6

s
I

z 13

Observation A nodes swap left 4 Dont child


tree setum the
the given
I invert
new root of that
och
y
Sc

Node invert Node not

nude tmp invert root right

not sht invert cot


not left Emp
setum soot

Q Check if it is possible to remove one edge from

so that both the resultant parts


given BT
have equal sum

ans Tue

A 23
d ans False
7

T
s
i

n f
Observation If tot sum is odd answer is False

One part is always be a subtree

S then each part will have


If tot sum
som 4
exists
If one sobbee with sum
3
Tme
else

False

int sum not


flooot NOLE return O
actin sum root left e som root sight root data

bool ans False

tetum the
sum of given subtree

in
p
subtreewith som woot int som

Ifcooot Nute return O

t 19 1 some not sight root data


if 502,40
Emp Sum ans Tae

g
TC O NTN OCN
Sc O CH
bool checkhay Node not

int s sum froot


f2 1 seam False
it IS
substeewithsomCot
setum ans

5 46

y 512 2

f É 5
6
anson

do fansy
em
Q Find Kth smallest element in BST
d
I based indexing

I
20

K B ans 7 IT 22
12 6 ans 21 I
21 50

1 hordes of BST sorted

Ans maintain a cat while doing inordes

12th number in Inorder

TC OCK SC O CHP
d
OCD morn's
a Given at BT given Given an next seances
are Noll

II
Node
find
int data
10 non

Node lest Gnu 120 non


node night

2
In 122 N
3
In In In so
Populate next reference
I

22 NHL 8,8 71,50


Noll
TC OCN
scioens
Queue node a

9 Push not 9 posh NOLL

while C E size a

If CX NOLL
q push NULL
else

tf C root left null q push root test

f Lfc soot sight


soot next
Enola 9 push Coot sigh

g fronted
O Check if the given BT has not deaf
equal to given K
path sum

5
µ go ans't
False
y to
12 50 ans

12 30 ans The

y s

goods

oof If this bee have a not hey


so ON
go µ path som K

Pathexist node not int K

FC Dot NULL

setum K 2 0

am pam

Pathexist 200 f night k not data


If
1 Ya

qt
Boot FC 5,60

1
I
78 fig 55
fly 55
f Ift
CA f 22,47
FC 11,51 M 51

TF
Ny
TF
JE I f 25,25
fennel Gi

finull o

f
I
51 C 113262

setum the Kiso


k s

schism false K is not zero

X x

You might also like