jagomart
digital resources
picture1_Hacking A Google Interview Practice Questions Person B


 160x       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 ...

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...

no reviews yet
Please Login to review.