HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Linear Data Structures: Arrays > problem:


51021 - Number of Nodes

Guest
• Review clarifications (2)

Section problems

• 50932 - Shifting rows and columns
• 50497 - Falling Bricks - Revisited
• 50933 - Sum of the Biggest Neighbors
• 50444 - n digit kth number divisible...
• 50865 - Apartment Building Adminis...
• 50874 - Apartment Building Adminis...
• 51127 - Maze solver
• 51126 - Dr. Fllanxha
• 51021 - Number of Nodes
• 51044 - Number of Trees
• 51098 - Rotate a matrix
• 51061 - The Longest Path
• 51083 - Grades Histogram
• 51084 - Reflect a matrix
• 51011 - Decoding the Path
• 51088 - Number of letters
• 51172 - The biggest Minute

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ibrahim Mesecan.

Number of Nodes

Question: Write a program that reads a BST, a node and a direction (Right or Left). Then, the program calculates number of nodes on the given direction of the given node.

Input specification: You will be two integers and a direction in the beginning,

  • number of nodes (n) to be added to the BST,
  • node to be searched in BST
  • the direction: a string which can be only "Right" or "Left"
Each of the following n-lines will have one integer where 0 ≤ n ≤ 40,000 and the numbers are between -5e6 and 5e6. Note: Assume that the BST is initially empty.

Output specification: If the searching number is in the BST, show the number of nodes in the given direction, show zero otherwise.

Sample Input I
7 14 Right
14
10
16
14
19
18
16
Sample Input II
10 18 Left
10
20
18
14
18
12
15
16
12
17
Sample Output I
3
Sample Output II
5



Для отправки решений необходимо выполнить вход.

www.contester.ru