TopCoder problem "TrophyShelf" used in SRM 386 (Division II Level One)



Problem Statement

    You have several trophies sitting on a shelf in a straight line. Their heights are given in a int[] trophies, from left to right. The shelf is positioned so that whenever people enter your room, they see it directly from the left side. In other words, the leftmost trophy is completely visible to the viewer, the next trophy in line is directly behind it, and so on.



Unfortunately, tall trophies near the left side of the shelf might block the view of other trophies. A trophy is visible only if every trophy in front of it (from the viewer's perspective) is strictly shorter than it is. You wonder if rotating the shelf 180 degrees would increase the number of visible trophies.



Return a int[] containing exactly two elements. The first element should be the number of trophies visible when viewing the shelf directly from the left side, and the second element should be the number of trophies visible when viewing the shelf directly from the right side.
 

Definition

    
Class:TrophyShelf
Method:countVisible
Parameters:int[]
Returns:int[]
Method signature:int[] countVisible(int[] trophies)
(be sure your method is public)
    
 

Constraints

-trophies will contain between 1 and 50 elements, inclusive.
-Each element of trophies will be between 1 and 100, inclusive.
 

Examples

0)
    
{1,2,3,4,5}
Returns: {5, 1 }
When viewed from the left, each trophy is taller than all the trophies in front of it. However, when viewed from the right, the first trophy blocks the view of all the other trophies.
1)
    
{5,5,5,5}
Returns: {1, 1 }
Since all trophies have the same height, only the first is visible when viewed from each direction.
2)
    
{1,2,5,2,1}
Returns: {3, 3 }
This trophy shelf is symmetric.
3)
    
{1,4,2,5,3,7,1}
Returns: {4, 2 }

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=8541

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=11120&pm=8541

Writer:

eleusive

Testers:

PabloGilberto , Olexiy , lovro , ivan_metelsky

Problem categories:

Simple Search, Iteration