Given a sequence of integers, there are a few sequences
which result in balanced
binary search trees i.e., AVL trees. Write a program that
takes a sequence of integers
as input and outputs the number of such sequences that
result in the balanced binary
search trees.
Input Format:
Single line contains sequence of integers terminated by -1.
Output format:
Print the number of AVL tree possible from that input sequence.
Sample Input:
1 2 3 -1
Sample Output:
2


No Answer is Posted For this Question
Be the First to Post Answer

Post New Answer

More Puzzles Interview Questions

Consider a state lottery where you get to choose 8 numbers from 1 to 80, no repetition allowed. The Lottery Commission chooses 11 from those 80 numbers, again no repetition. You win the lottery if at least 7 of your numbers are there in the 11 chosen by the Lottery Commission. What is the probability of winning the lottery?

2 Answers  


There is a perfect sphere of diameter 40 cms. resting up against a perfectly straight wall and a perfectly straight floor i.e. the wall and the floor make a perfect right angle. Can a perfect sphere of diameter 7 cms. pass through the space between the big sphere, the wall and the floor? Support your answer with valid arguments. Don't submit just "Yes" or "No".

3 Answers  


What is the smallest whole number that, when divided by 2, leaves a remainder of 1; when divided by 3, leaves a remainder of 2; and so on, up to leaving a remainder of 9 when divided by 10?

24 Answers   ASD Lab, Athena Health Care,


x^y+y^x=5298.If x and y are integers find x and y.

1 Answers  


Given an N × N array of positive and negative integers, find the sub-rectangle with the largest sum. The sum of a rectangle is the sum of all the elements in that rectangle. In this problem the sub-rectangle with the largest sum is referred to as the maximal sub-rectangle. A sub-rectangle is any contiguous sub-array of size 1 × 1 or greater located within the whole array. Input Format: First line contains the size of matrix. Followed by n lines and each line contain n integers separated by space. Output format: Single integer which represents maximum sum of rectangle. Sample Input: 4 0 -2 -7 0 9 2 -6 2 -4 1 -4 1 -1 8 0 -2 Sample Output: 15

1 Answers   Infosys, TCS,






There are four friends, one weekend they plan to go to a picnic. Each family have husband and wife with two kids each, further each kid has 2 pets. Total how many went to the picnic?

1 Answers  


i want model paper on SBI Clerk post,plz sed previous papers

0 Answers   State Bank Of India SBI,


If you are in a jail. there a window having two rodes one is made of Iron and other is of magnet. using a rope how could you find magnet or iron rod.

4 Answers  


In a sports contest there were m medals awarded on n successive days (n > 1). 1. On the first day 1 medal and 1/7 of the remaining m - 1 medals were awarded. 2. On the second day 2 medals and 1/7 of the now remaining medals was awarded; and so on. 3. On the nth and last day, the remaining n medals were awarded. How many days did the contest last, and how many medals were awarded altogether?

2 Answers  


A fly is flying between two trains, each travelling towards each other on the same track at 60 km/h. The fly reaches one engine, reverses itself immediately, and flies back to the other engine, repeating the process each time. The fly is flying at 90 km/h. If the fly flies 180 km before the trains meet, how far apart were the trains initially?

3 Answers  


In country X, democratic, conservative and justice parties have fought three civil wars in twenty years. TO restore stability an agreement is reached to rotate the top offices President, Prime Minister and Army Chief among the parties so that each party controls one and only one office at all times. The three top office holders must each have two deputies, one from each of the other parties. Each deputy must choose a staff composed of equally members of his or her chiefs party and member of the third party. 1. When Justice party holds one of the top offices, which of the following cannot be true (a) Some of the staff members within that office are justice party members (b) Some of the staff members within that office are democratic party members (c) Two of the deputies within the other offices are justice party members (d) Two of the deputies within the other offices are conservative party members (e) Some of the staff members within the other offices are justice party members. 2. When the democratic party holds presidency, the staff of the prime minister's deputies are composed I. One-fourth of democratic party members II. One-half of justice party members and one-fourth of conservative party members III. One-half of conservative party members and one-fourth of justice party members. (a) I only (b) I and II only (c) II or III but not both (d) I and II or I and III (e) None of these 3. Which of the following is allowable under the rules as stated: (a) More than half of the staff within a given office belonging to a single party (b) Half of the staff within a given office belonging to a single party (c) Any person having a member of the same party as his or her immediate superior (d) Half the total number of staff members in all three offices belonging to a single party (e) Half the staff members in a given office belonging to parties different from the party of the top office holder in that office. 4. The office of the Army Chief passes from Conservative to Justice party. Which of the following must be fired. (a) The democratic deputy and all staff members belonging to Justice party (b) Justice party deputy and all his or hers staff members (c) Justice party deputy and half of his Conservative staff members in the chief of staff office (d) The Conservative deputy and all of his or her staff members belonging to Conservative party (e) No deputies and all staff members belonging to conservative parties.

0 Answers  


If a rook and a bishop of a standard chess set are randomly placed on a chessboard, what is the probability that one is attacking the other? Note that both are different colored pieces.

1 Answers  


Categories