behinddwalls
BAN USER- 3of 3 votes
AnswersGiven a binary tree. Modify it in such a way that after modification you can have a preorder traversal of it using only right pointers. During modification you can use right as well as left pointers. Write complete code and dry run it for some test cases
- behinddwalls in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Trees and Graphs - 0of 0 votes
AnswersFind cousins of a given node in a Binary tree and BST.
My Approach:
- behinddwalls in United StatesSteps:(Using level order Traversal) 1. Create a queue q and en-queue root element and take variable qSize and a flag=true 2. Start a loop and check queue is empty or not { if qSize==0 then qSize=q.size(); if not flag then print the current queue (q) Start one more loop and check for qSize>0 { qSize-- x=deque(); if((x.left != null && x.left== key) || (x.right!= null && x.right== key)) { flag=false continue } enqueue(x.left) enqueue(x.right) } }
| Report Duplicate | Flag | PURGE
Amazon SDE1 Trees and Graphs - 0of 0 votes
AnswersWhich data structure will be used for storing a friend list for a social networking site..like facebook
- behinddwalls in United States| Report Duplicate | Flag | PURGE
Application / UI Design
can u xplain it in form code ?
- behinddwalls April 11, 2013what type of schema...may i know?
- behinddwalls August 11, 2012
Repbehinddwalls, Computer Scientist at Belzabar Software Design
Repbehinddwalls, Computer Scientist at Belzabar Software Design
Probably we can use the Summation formula for Arithmetic series to find if the given sequence is arithmetic or not?
- behinddwalls March 02, 2016S= n/2(2*a + (n-1)d)
Steps:
- Find the smallest & second smallest element in the array
- Now you have a and d.
- Also calculate the sum of the all the elements in array.
- Check if sum of the array elements is same as the sum you get using formula.
For Base Cases:
if array size is 1 then just return true