Star elements
Easy Accuracy: 42.89% Submissions: 585 Points: 2

Given an unsorted array arr of size n. The task is to find all the star and super star elements in the array. Star are those elements which are strictly greater than all the elements on its right side. Super star are those elements which are strictly greater than all the elements on its left and right side.

Note: Assume first element (arr[0]) is greater than all the elements on its left side, And last element (arr[n-1]) is greater than all the elements on its right side.

Example 1:

Input:
n = 10
arr[] = {1, 6, 5, 4, 7, 8, 4, 3, 2, 1}
Output: 
8 4 3 2 1 
8
Explanation: Star elements are 8, 4, 3, 2 and 1.
Super star element is 8.

Example 2:

Input:
a = 9
arr[] = {1, 2, 10, 3, 4, 5, 8, 10, 4}
Output: 
10 4 
-1
Explanation: Star elements are 10 and 4.
No super star element present here.

Your Task:
You don't need to read input or print anything. Your task is to complete the function getStarAndSuperStar() which takes the array of integers arr and as parameters and returns an array of integers denoting the answer where first element is the super star element and rest are star elements. Return -1 in first element of the array if no super star element is present. The driver code itself prints the star elements in first line and super star element in second line.

Expected Time Complexity: O(n)
Expected Auxiliary Space: O(1)

Constraints:
1 <= n <= 106
1 <= arr[i] <= 106

 

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Star elements

Output Window