Huawei OD machine test - raindrop effect of 2D umbrella (Java & JS & Python)

topic description

Ordinary umbrellas in the two-dimensional plane world have a side on the left and right sides, and there is an umbrella pendant at the bottom of the umbrella sides on both sides. When the raindrops fall on the umbrella surface and gradually flow to the pendant, the information of the pendant will be sent to the umbrella pendant. Carry it and fall to the ground, as time goes on, the ground will show the information of the umbrella falling.

1. In order to simulate the umbrella-like raindrop effect, use a binary tree to simulate a two-dimensional plane umbrella (as shown in the figure below), now input a string of positive integer array sequences (excluding 0, and the array members must be at least 1), if the array sequence is The result of the preorder traversal of the binary search tree, then please output a return value of 1, otherwise output 0.

2. At the same time, please output the digital information of the umbrella effect formed by this sequence to the ground (left umbrella drop information, right umbrella drop information, refer to the number on the ground in the example picture for details), if there is no left or right fan drop in this tree, Then the corresponding position returns 0. At the same time, if it is not a binary sorting tree, then the left and right parachute information also returns 0.

enter description

An integer sequence string separated by spaces, the array does not contain 0, the array member must be at least 1, any two numbers in the input array are different from each other, up to 1000 positive integers, and the value range of positive integers is 1~65535

output description

Output the following three values, separated by spaces: whether or not to be a binary sort tree, the digital value of the umbrella pendant displayed on the left ground, and the digital value of the umbrella pendant presented on the right ground.

If it is a binary sorting tree, output 1, otherwise output 0 (the left

Guess you like

Origin blog.csdn.net/qfc_128220/article/details/132657754