Given a binary tree, return the values of its boundary in anti-clockwise direction starting from root. Boundary includes left boundary, leaves, and right boundary in order without duplicate nodes. (The values of the nodes may still be duplicates.)
Left boundary is defined as the path from root to the left-most node. Right boundary is defined as the path from root to the right-most node. If the root doesn’t have left subtree or right subtree, then the root itself is left boundary or right boundary. Note this definition only applies to the input binary tree, and not applies to any subtrees.
The left-most node is defined as a leaf node you could reach when you always firstly travel to the left subtree if exists. If not, travel to the right subtree. Repeat until you reach a leaf node.
The right-most node is also defined by the same way with left and right exchanged.
Example 1
Input: 1 \ 2 / \ 3 4 Ouput: [1, 3, 4, 2] Explanation: The root doesn't have left subtree, so the root itself is left boundary. The leaves are node 3 and 4. The right boundary are node 1,2,4. Note the anti-clockwise direction means you should output reversed right boundary. So order them in anti-clockwise without duplicates and we have [1,3,4,2]. |
Example 2
Input: ____1_____ / \ 2 3 / \ / 4 5 6 / \ / \ 7 8 9 10 Ouput: [1,2,4,7,8,9,10,6,3] Explanation: The left boundary are node 1,2,4. (4 is the left-most node according to definition) The leaves are node 4,7,8,9,10. The right boundary are node 1,3,6,10. (10 is the right-most node). So order them in anti-clockwise without duplicate nodes we have [1,2,4,7,8,9,10,6,3]. |
The solution to this problem can be constructed using 3 sets:-
- Left boundary
- Leaf Nodes (left to right)
- Right boundary
Generating these sets is straightforward but we need to be mindful of double counting nodes.
- Left boundary and right boundary will contain root so best to separate that out.
- Left boundary’s leftmost node will also be a leaf node (same for right boundary’s rightmost node). Again, best to remove these from those sets.
Our solution will be concatenation of
- Root Node
- Left Boundary Nodes (without the last leaf node)
- Leaf nodes (from left to right)
- In reverse, Right Boundary Nodes (without the last leaf node)
/** * Definition for a binary tree node. * function TreeNode(val, left, right) { * this.val = (val===undefined ? 0 : val) * this.left = (left===undefined ? null : left) * this.right = (right===undefined ? null : right) * } */ /** * @param {TreeNode} root * @return {number[]} */ // get all leaf nodes (left to right) var preOrder = function(root, level, leafs) { if (!root) return; if (!root.left && !root.right && level !== 0) leafs.push(root.val); preOrder(root.left, level+1, leafs); preOrder(root.right, level+1, leafs); } var boundaryOfBinaryTree = function(root) { if (!root) return []; // get all left boundary nodes let leftList = []; let curr = root.left; while (curr) { leftList.push(curr.val); if (curr.left) curr = curr.left; else curr = curr.right; } // without the leftmost leaf (because that will already be part of the leaf's list) leftList.pop(); // get all right boundary nodes let rightList = []; curr = root.right; while (curr) { rightList.push(curr.val); if (curr.right) curr = curr.right; else curr = curr.left; } // without the rightmost leaf (because that will already be part of the leaf's list) rightList.pop(); // get all leaf nodes let leafList = []; preOrder(root, 0, leafList); // Solution is: // Root All_Left_Nodes All_Leaf_Nodes Reverse(All_Right_Nodes) // Remember to remove last leaf node from All_Left_Nodes and All_Right_Nodes otherwise you will double count! return ([root.val]). concat(leftList). concat(leafList). concat(rightList.reverse()); }; |
buy cephalexin 250 mg
metformin 397
synthroid pharmacy
toradol 2017
zestoretic 20 25
how much is zofran cost
synthroid 0.01mg
singulair medication
chloroquine over the counter uk
bactrim australia
bactrim cream
ivermectin 9mg
albendazole 400mg
cost of ivermectin pill
buy ivermectin uk
zestoretic medication
albendazole buy
400 mg albendazole
ventolin generic brand
synthroid canada price
bactrim tablets 480 mg
online drugs
albenza pinworms
metformin 1000 mg tablet price in india
erythromycin 333 cost
buy toradol online no prescription
ventolin usa over the counter
cheap albenza
chloroquine covid 19
buspar for sale
purchase flomax online
lexapro cost in india
prescription drugs canadian
retino
sildalis
valsartan hydrochlorothiazide
buy lyrica 150mg
hydrochlorothiazide where to buy
prednisolone uk
pharmacy express online
lyrica medication cost
prescription drug costs
albenza 200 mg coupon
clonidine 0.5
seroquel xr patient assistance
buspar 300 mg
proventil hfa 90 mcg inhaler
lexapro 5 mg tablet
trental 400 1mg
indocin for sale
buy colchicine 500 mg
pharmacy express
avodart drug
best advair price
buy vermox in usa
canadian world pharmacy
brand name benicar cost
ampicillin tablet 500mg
generic vermox
budesonide from canada
thecanadianpharmacy com
us pharmacy
can you buy advair over the counter
anafranil 75 mg price
prednisolone tablets 4mg
retino 0.25
vermox 500mg tablet
prednisolone tablets 25mg price
pharmacy price comparison
ampicillin medication
citalopram brand name in canada
medrol tabs
medrol online
chloroquine tablets buy
citalopram 200 mg tablets
zestoretic 5 mg
toradol gel
ampicillin 500mg
citalopram hydrobromide 20 mg
cephalexin 500mg tablets
chloroquine price in india
benicar 20 5 mg
digoxin tablet
where can i buy lexapro online
benicar 40
where to buy colchicine without a prescription
top 10 pharmacies in india
digoxin 0.125 mg tab
can you buy phenergan over the counter
azithromycin 250 mg pill
buy lanoxin online
digoxin 0.125mcg
how much is lexapro
advair generic brand
sildalis for sale
vermox australia
lanoxin cost
colchicine brand
bactrim brand name
zestoretic 10 12.5
suhagra 25 mg price
atenolol 50 mg price in india
0.2 clonidine
ordering atenolol online
phenergan otc nz
cheap tadacip
toradol iv
synthroid brand name price
pharmacy order online
drug clonidine
buy tadacip 20 mg
generic zofran cost
tadacip
best price for lexapro
Superb info. Thanks. https://canadapharmacies-24h.com/
prednisolone brand name uk
avodart mexico
which pharmacy is cheaper
buying buspar
buy prescription drugs canada
combivent price in india
You actually reported that really well. https://canadapharmacies-24h.com/
You actually said this terrifically. https://canadapharmacies-24h.com/
Amazing info. Thanks! https://canadapharmacies-24h.com/
Awesome info. Appreciate it! https://canadapharmacies-24h.com/
You made your point quite well.. https://canadapharmacies-24h.com/
anafranil 50 mg capsule
With thanks. Fantastic stuff! https://canadapharmacies-24h.com/
medrol 4mg tablets
Really quite a lot of useful data. https://canadapharmacies-24h.com/
lexapro drug
Thanks! I value this! https://canadapharmacies-24h.com/
Thank you! Ample forum posts.
https://canadapharmacies-24h.com/
motilium cost
can i buy bactrim online
Beneficial tips. Regards! https://canadapharmacies-24h.com/
tadacip 20 mg online india
hydrochlorothiazide 25 mg price
malegra 100 for sale
where to buy retin a online uk
lyrica 150 mg
where can you get elimite
Truly a lot of beneficial info. https://canadapharmacies-24h.com/
thecanadianpharmacy com
25 mg anafranil online
buy citalopram 10mg online uk
buspar 150 mg daily
Info nicely considered.! https://canadapharmacies-24h.com/
erectafil
vermox uk
albendazole prescription
You actually stated that effectively! https://canadapharmacies-24h.com/
You said it very well.. https://canadapharmacies-24h.com/
phenergan tablets
Nicely put. Cheers. https://canadapharmacies-24h.com/
zestoretic 20
delagil
Thanks a lot, Terrific information! https://canadapharmacies-24h.com/
atarax canada
metformin 1000 mg price india
brand name nexium canada
erectafil 10
brand name prednisolone
malegra fxt online
metformin 1250 mg
anafranil medicine
aralen phosphate chloroquine phosphate
dexamethasone canada
albendazole 200 mg coupon
phenergan online australia
estrace cream
predisolone online
price of phenergan
buy atarax tablets
bactrim cost in india
nexium 20 mg price uk
albendazole 2g
malarex
phenergan 30 mg
lexapro
phenergan 10mg tab
tadacip 20 india
motilium over the counter australia
aurogra 100mg tablets
lyrica 450 mg
fildena tablets
albenza pinworms
erectafil 2.5
singulair chewable tablets
buy singulair 10mg online
erectafil 20 online
buy atarax online
Truly lots of terrific facts! https://canadapharmacies-24h.com/
generic cost of seroquel
You made your stand quite effectively.! https://canadapharmacies-24h.com/
allopurinol pills 100mg
where to buy ampicillin
Whoa loads of wonderful info! https://canadapharmacies-24h.com/
allopurinol 300 mg over the counter
Whoa many of useful data! https://canadapharmacies-24h.com/
vermox otc uk
Useful information. Thanks! https://canadapharmacies-24h.com/
vermox otc canada
Very good forum posts. Regards. https://canadapharmacies-24h.com/
canadianpharmacymeds com
retino
You said it adequately.. https://canadapharmacies-24h.com/
fildena canada
Valuable material. Kudos. https://canadapharmacies-24h.com/
retino 05 cream
where can i buy vermox tablets
ampicillin purchase
motrin 8
combivent respimat cost
molnupiravir france
seroquel price australia
30 hydrochlorothiazide 25 mg
Many thanks, I like this. https://canadapharmacies-24h.com/
trental coupon
allopurinol online
antabuse cost uk
Cheers! I appreciate it. https://canadapharmacies-24h.com/
hydrochlorothiazide brand name in india
tadacip online uk
yasmin 28 pills
Useful tips. Thank you. https://canadapharmacies-24h.com/
triamterene
antabuse prescription drug
You actually explained that well. https://canadapharmacies-24h.com/
motrin 300
allopurinol online india
Really lots of beneficial information. https://canadapharmacies-24h.com/
estrace 1 mg
buspar buy
Nicely voiced without a doubt. ! https://canadapharmacies-24h.com/
cheap prednisolone
vermox us
You made your point pretty effectively!. https://canadapharmacies-24h.com/
order vermox
Really a lot of helpful information. https://canadapharmacies-24h.com/
75 mcg synthroid no prescription
budesonide tablets australia
Regards! Awesome stuff. https://canadapharmacies-24h.com/
Point nicely taken.. https://canadapharmacies-24h.com/
You actually expressed this very well! https://canadapharmacies-24h.com/
You actually revealed this superbly. https://canadapharmacies-24h.com/
Kudos! Loads of facts.
https://canadapharmacies-24h.com/
Wow loads of beneficial tips. https://canadapharmacies-24h.com/
ivermectin 6 mg tablets
buy anafranil in india
lexapro
malegra dxt
nexium cream
You’ve made your stand extremely effectively.. https://canadapharmacies-24h.com/
synthroid 75 pill
tadacip 10 mg price
budesonide gel
vermox over the counter
bactrim antibiotic online prescriptions
zestoretic 20
deepdotweb markets verified dark web links
buy yasmin online india
lyrica capsules price
darknet markets wax weed dark markets croatia
darknet markets norway 2022 vice city market url
top darknet market 2022 versus project market darknet
Cocorico Market darknet drug markets 2022
new darknet market reddit reddit darknetmarket
darkweb markets dark markets croatia
deep cp links darknet drugs
darknet market pills vendor onion market url
access the black market the dark web links 2022
darknet drugs sites deep dot web markets
новое зеркало мега mega зеркало
how to use onion sites bohemia market url
dark market onion versus market darknet
darknet search engine darknet black market list
counterfeit euro deep web best market darknet drugs
darknet market adressen Heineken Express Market
mega онион сайт мега
deep web marketplaces reddit 2022 darknet markets
the dark web url darknet markets dread
alphabay link deep web addresses onion
top darknet markets 2022 alphabay darknet market
buying credit cards on dark web adresse onion
reddit darknet market uk
access the dark web reddit drug website dark web
mega onion мега onion зеркало
dark web market reviews versus market url
assassination market darknet dark web vendors
darknetlive deep deep web links
darknet market updates 2022 cypher market url
dark markets moldova buy darknet market email address
darknet site darknet drug delivery
мега нарко мега вход
dark market links how to get to darknet market
darknet adress dark markets malaysia
tor markets dark markets spain
darknet market avengers darknet markets that take ethereum
core market darknet buying darknet drugs
сайт даркнет даркнет ссылки
darknet telegram group dark markets france
trusted darknet markets weed safe darknet markets
reddit darknet markets links best darknet markets
anafranil canada
mega даркнет mega зеркало
archetyp url asap market link
darknet drugs sales working dark web links
monero darknet markets carding deep web links
monkey x pill dark markets south korea
Abacus Market link deep web deb
мега мефедрон мега кокаин
best dark web markets reddit darknet markets list
dma drug darknetlive
marijuana dark web darknet drugs 2022
dark markets uk tor2door market darknet
2022 working darknet market buying drugs on the darknet
black market deep
deep web cc sites dark markets turkey
asap market darknet dark markets netherlands
darknet market reddits most popular darknet markets 2022
darknet market forum tor markets 2022
buy proscar australia
официальный сайт мега мега onion
dark markets peru onion deep web search
dark market 2022 darknet market place search
reddit darknet market noobs bible darknet markets 2022 updated
сайт даркнет мега онион сайт
darkfox market link darknet market superlist
dark web drug markets darknet drug trafficking
buying from darknet market with electrum darknet marketplace drugs
legit darknet sites darknet drug markets
archetyp market darknet tor market list
best darknet market for psychedelics darknet drugs market
mega онион сайт mega onion
darknet live markets the dark market
dark markets belarus what is the darknet market
dark market 2022 black market cryptocurrency
free deep web links onion links for deep web
search deep web engine darknet market list links
best darknet market 2022 Abacus darknet Market
how to access the darknet market how to access the dark web on pc
мега вход mega онион
top ten dark web sites dark market url
darknet market noobs bible cannazon market link
black market access australian dark web vendors
new darknet markets 2022 best dark web marketplaces 2022
versus project link
list of dark net markets archetyp url
best darknet market now tor drugs
best dark web markets dark web uk
deep cp links asap market link
site darknet onion reddit darknet markets noobs
darknet market search darknet black market list
grey market darknet darknet market and monero
bitcoin market on darknet tor onion link reddit
mega онион сайт мега кокаин
what darknet markets are live tor darknet market address
carding dark web dark websites reddit
deep web drugs darknet market updates 2022
dark markets netherlands underground website to buy drugs
dark web buy credit cards buy drugs online darknet
biggest darknet markets 2022 list of dark net markets
brick market what is escrow darknet markets
dark market link dark web link
dark markets spain access the dark web reddit
top ten dark web where to find darknet market links
reddit darknet markets noobs deep dot web links
deep web weed prices dream market darknet url
incognito market url darknet market lists
tma drug dark markets ecuador
bohemia link drugs on the darknet
мега сайт мега сайт
carding dark web
darknet websites list 2022 reddit darknet market list 2022
мега шишки мега наркотики
darknet steroid markets dark net market links 2022
canazon deep web software market
tor dark web gbl drug wiki
Heineken Express darknet Market marijuana dark web
cypher darknet market tor2door market
darknet litecoin dark markets mexico
darknet markets list reddit russian darknet market
dark web link links da deep web 2022
most popular darknet market tor websites reddit
onion deep web wiki reddit darknet market uk
mega онион мега нарко
darknet markets japan darkweb форум
мега вход mega даркнет
cannahome market url largest darknet market
tor search engine link reddit darknet market how to
dark web onion markets buds express
deep web link 2022 carding dark web
black market drugs how to access darknet markets
credit card dark web links credit card dark web links
dark web steroids largest darknet market
new darknet markets 2022 darknet guns drugs
darknet markets with tobacco darknet escrow markets
what darknet markets are live hacking tools darknet markets
darknet market wikia dark web search engines link
the darknet markets darknet market for noobs
black market websites 2022 best current darknet market
how to access deep web safely reddit darknet drug dealer
dark web in spanish
canazon dark markets macedonia
mega онион сайт мега onion оффициальный сайт
best darknet marketplaces monkey xtc pill
darknet markets list reddit darknet market ranking
dark markets france archetyp market link
market links darknet deep web deb
dark market links best darknet market for counterfeit
deep web drug prices dark web markets reddit
drugs dark web reddit back market legit
black market illegal drugs darknet market reviews
uncensored deep web which darknet markets are up
deep web trading accessing darknet market
french dark web dark markets ukraine
deep web url links dark web market links
best darknet market for weed black market drugs
dark markets south korea deep web drug store
biggest darknet market 2022 current best darknet market
dma drug darknet drug markets 2022
mega онион мега онион
darkshades marketplace dark markets
dark web search engines link darknet market list links
drugs dark web reddit darknet links 2022 drugs
cheapest drugs on darknet list of dark net markets
darknet market url list asap market link
counterfeit euro deep web darknet market redit
darknet market reddit list cypher market url
darkmarket link litecoin darknet markets
onion directory
tor onion search how to buy from the darknet markets lsd
mega зеркало сайт даркнет
online black market electronics best darknet market 2022 reddit
reddit darknet market noobs darknet in person drug sales
buying drugs off darknet dark web engine search
the darknet markets darknet markets list reddit
dark markets thailand agora darknet market
buying drugs online on openbazaar dark markets moldova
mega сайт мега даркнет
albendazole cost australia
darknet market reddit incognito market url
how to use onion sites dark markets switzerland
мега кокаин мега наркотики
dark markets slovakia darknet drug markets reddit
darknet markets ranked 2022 dark web engine search
dark web links reddit dark markets portugal
darknet markets urls how to get to darknet market safe
drugs dark web reddit darknet drugs links
archetyp link darknet drug markets
dark web markets black market website
most popular darknet market online drug market
deep web drugs best mdma vendor darknet market reddit
top onion links
darknet drug market darknet market controlled delivery
dark markets croatia darknet market guide
dark web links 2022 reddit tor darknet sites
darknet market list links phenethylamine drugs
darknet search engine url how to access darknet markets
alphabay link reddit what darknet market to use
darknet market alternatives credit card black market websites
dark web electronics darknet market updates 2022
darknet market controlled delivery darknet markets florida
onion seiten 2022 escrow dark web
dark market sites deep web links reddit 2022
darknet market pills vendor darknet prices
buy darknet market email address adresse onion black market
legit onion sites active darknet markets 2022
darknet live markets deep web drug links
safe darknet markets the darknet markets
crypto market darknet darknet market listing
darknet drugs price trusted darknet markets
darknet cannabis markets dark web markets reddit 2022
dark markets norway darknet market drug prices
dynabolts pills darknet sites drugs
buy antabuse online safely
darknet vendor reviews the onion directory
i2p darknet markets
buy bitcoin for dark web good dark web search engines
fake id dark web 2022 deep web links updated
darknet market thc oil drug market darknet
darknet market list reddit dread onion
dark web market list deep web drugs
darkweb markets darkmarket list
onion links for deep web outlaw darknet market url
safe darknet markets onion darknet market
Cocorico Market darknet darknet market reddit 2022
darknet markets without login links tor 2022
asap market link shop on the dark web
decentralized darknet market grey market link
black market net dark web drugs ireland
best black market websites darknet market news
best darknet market australia Cocorico link
what darknet markets still work hacking tools darknet markets
how to access darknet markets reddit darknet websites list 2022
ruonion bitcoin darknet markets
how to pay with bitcoin on dark web how to access darknet market
project versus darknet drugs sites
top darknet markets 2022 reddit darknet market uk
dark markets uruguay darknet seiten liste
tor link list 2022 tor market
links da deep web 2022 darknet wiki link
best tor marketplaces dark web search engine 2022
hidden wiki tor onion urls directories darknet market comparison
мега онион сайт мега onion зеркала
new darknet marketplaces darknet vendor reviews
top onion links dark web markets 2022 australia
darknet markets japan best dark web markets
mdm love drug buy drugs online darknet
dark web sites links deep web links updated
largest darknet market black market sites 2022
archetyp market how to browse the dark web reddit
dark markets montenegro site darknet fermГ©
drug trading website darknet illegal market
darknet markets list 2022 cannazon market link
мега даркнет mega онион сайт
tor search engine link darknet drugs market
darknet drug links link darknet market
dark web engine search current list of darknet markets
drugs on deep web best darknet drug market 2022
counterfeit money dark web reddit darknet market wiki
darknet links markets best mdma vendor darknet market reddit
darknet guns market how to buy drugs on darknet
online drug market escrow dark web
dark markets argentina deep web link 2022
dark web escrow service tor search engine link
drug market dark markets greece
dark market reddit darknet drug markets reddit
dark web market place links superlist darknet markets
darknet drugs guide best darknet market urs
tor onion search
darknet markets address adresse onion
current list of darknet markets dark markets mexico
uncensored hidden wiki link list of darknet markets reddit
deep web deb Kingdom Market darknet
the armory tor url darknet guns market
deep dark web buy bank accounts darknet
darknet links markets darkfox link
deep web directory onion dark markets belarus
darknet markets best top 10 dark websites
drugs dark web dark markets andorra
asap link dark markets mexico
dark markets philippines carding dark web
onion link search engine dark markets macedonia
mega сайт мега мефедрон
dark markets new zealand darknet market
best darknet market reddit darknet market reddit 2022
dark web steroids incognito darknet market
pill with crown on it darknet market buying mdma usa
french deep web link escrow dark web
redit safe darknet markets darknet markets availability
dark markets deep dark web
Kingdom Market Cocorico link
cypher market link updated darknet market links 2022
сайты даркнет мэги сайт
buy drugs darknet reddit darknet market guide
reddit best darknet market bohemia darknet market
buying drugs on darknet dark market onion
live onion
darknet drugs url Heineken Express darknet Market
tor darknet market address price of black market drugs
drug markets onion tor2door market url
Cocorico Market link new alphabay darknet market
best darknet market reddit darknet onion markets
mega онион сайт сайты даркнет
dark web step by step buy darknet market email address
drugs darknet vendors uncensored hidden wiki link
how to buy drugs on the darknet wiki darknet market
Kingdom Market darknet deep web links updated
incognito market darknet drugs dark web
links the hidden wiki tor2door market
best working darknet market 2022 berlin telegram group drugs
popular darknet markets access darknet markets
мега шишки мега onion
darknet market list deep web link 2022
how to get to darknet market safe gbl drug wiki
cannazon url reddit working darknet markets
live dark web darknet markets list reddit
live onion best darknet market for steroids
dark web markets reddit Abacus Market darknet
dark web drugs nz dark markets peru
incognito darknet market Kingdom link
how to access darknet markets core market darknet
cannahome url darknet market url
darknet market carding onion seiten 2022
dark markets estonia dn market
black market alternative
popular dark websites exploit market darknet
how to access the dark web through tor dark net market list
grey market drugs vice city darknet market
drugs on deep web dream market darknet url
where to find darknet market links darknet market google
onion websites for credit cards deep web weed prices
live onion dark web electronics
working dark web links tor2door link
cannahome url dark markets korea
darknet market ranking phenylethylamine
tor market dark web drug marketplace
tor market dark website
dark website dark web drug marketplace
best darknet markets deep web drug markets
мега сайт мега онион
tor dark web deep web sites
dark web sites darknet seiten
dark web access darkmarket list
albendazole pharmacy
bitcoin dark web deep web drug links
para que sirve el bactrim
dark web market darkmarket
tor market links dark market url
darknet market links tor markets 2022
1600 mg bactrim
dark web market list tor markets links
bitcoin dark web darkmarket
deep web sites drug markets dark web
tor dark web dark web link
dark web sites links deep dark web
dark markets 2022 free dark web
darkmarket list dark web sites
buy ampicillin online
darknet marketplace dark markets
dark markets tor market url
darknet seiten dark markets
dark web market list dark web site
the dark internet dark markets
darkmarket url dark web sites links
deep web drug url deep web sites
dark market list dark market url
the dark internet dark web markets
dark web drug marketplace darknet marketplace
dark web site dark web link
onion market dark web market links
dark web sites links dark markets 2022
dark web link dark web site
darkmarkets tor markets links
darknet drugs dark net
darknet sites darknet drug store
darkweb marketplace onion market
mega onion оффициальный сайт мега onion зеркала
tor markets 2022 dark web link
deep web drug url deep web drug links
drug markets dark web darknet market
darknet seiten the dark internet
dark market 2022 dark web access
darknet websites tor dark web
dark web site dark web site
darknet websites dark markets
darkmarket 2022