jagomart
digital resources
picture1_Hacking A Google Interview Practice Questions Person B


picture2_Hacking A Google Interview Practice Questions Person B picture3_Hacking A Google Interview Practice Questions Person B

 133x       Filetype PDF       File size 0.07 MB       Source: courses.csail.mit.edu


File: Hacking A Google Interview Practice Questions Person B
HackingaGoogleInterviewPracticeQuestions– PersonB Question:BinarySearchTreeValidity Writeafunctiontodeterminewhetheragivenbinarytreeofdistinctintegersisa validbinarysearchtree.Assumethateachnodecontainsapointertoitsleftchild,a pointertoitsrightchild,andaninteger,butnotapointertoitsparent.Youmayuse anylanguageyoulike. GoodAnswer:Notethatit'snotenoughtowritearecursivefunctionthatjustchecks iftheleftandrightnodesofeachnodearelessthanandgreaterthanthecurrent node(andcallsthatrecursively).Youneedtomakesurethatallthenodesofthe subtreestartingatyourcurrentnodearewithinthevalidrangeofvaluesallowedby thecurrentnode'sancestors.Thereforeyoucansolvethisrecursivelybywritinga helperfunctionthatacceptsacurrentnode,thesmallestallowedvalue,andthe largestallowedvalueforthatsubtree.Anexampleofthisisthefollowing(inJava): boolean isValid(Node root) { ...

icon picture PDF Filetype PDF | Posted on 05 Feb 2023 | 2 years ago
Partial capture of text on file.

						
									
										
									
																
													
					
The words contained in this file might help you see if this file matches what you are looking for:

...Hackingagoogleinterviewpracticequestions personb question binarysearchtreevalidity writeafunctiontodeterminewhetheragivenbinarytreeofdistinctintegersisa validbinarysearchtree assumethateachnodecontainsapointertoitsleftchild a pointertoitsrightchild andaninteger butnotapointertoitsparent youmayuse anylanguageyoulike goodanswer notethatit snotenoughtowritearecursivefunctionthatjustchecks iftheleftandrightnodesofeachnodearelessthanandgreaterthanthecurrent node andcallsthatrecursively youneedtomakesurethatallthenodesofthe subtreestartingatyourcurrentnodearewithinthevalidrangeofvaluesallowedby thecurrentnode sancestors thereforeyoucansolvethisrecursivelybywritinga helperfunctionthatacceptsacurrentnode thesmallestallowedvalue andthe largestallowedvalueforthatsubtree anexampleofthisisthefollowing injava boolean isvalid root return isvalidhelper integer min value max curr int if left null false right true therunningtimeofthisalgorithmiso n oddmanout you regivenanunsortedarrayofintegerswhereeve...
Haven't found the file you're looking for? You can try sending a request file
Comment

no comments yet
Please Login to post a comment.

no reviews yet
Please Login to review.