#C5815. Visible Trees from Left
Visible Trees from Left
Visible Trees from Left
Given (n) trees in a row with heights (h_1, h_2, \ldots, h_n), a tree is visible from the left if it is taller than every tree before it. Your task is to determine the number of visible trees and list their heights.
Input consists of an integer (n) (the number of trees) followed by (n) space-separated integers denoting the heights.
Output the count of visible trees on the first line and the visible tree heights (in order) on the second line.
For example, if (n = 5) and the heights are [2, 5, 3, 4, 1], then the visible trees are 2 and 5.
inputFormat
The first line contains an integer (n) representing the number of trees. The second line contains (n) space-separated integers (h_1, h_2, \ldots, h_n) indicating the heights of the trees.
outputFormat
Print the number of visible trees on the first line. On the second line, print the heights of the visible trees in the order they appear, separated by spaces. If no tree is visible, print an empty second line.## sample
5
2 5 3 4 1
2
2 5
</p>