FastPrepArray Leader Elements
Problems/Array Leader Elements

Array Leader Elements

Accenture logoAccenture● EasyNEW GRADOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names a leader-element task but leaves the singular-versus-all output and bounds unstated. This judged version returns every strict leader and matches the reported core task at about 85%.

Given an integer array nums, return every leader element in its original left-to-right order.

An element nums[i] is a leader when it is strictly greater than every element to its right. The final element is always a leader because no elements follow it.

If equal values occur, an earlier value is not a leader when the same value appears to its right.

Function

findLeaders(nums: int[]) → int[]

Examples

Example 1

nums = [16,17,4,3,5,2]return = [17,5,2]

17 is greater than every value after it. The same is true for 5 and the final value 2. Each other value has a larger value somewhere to its right.

Example 2

nums = [9,7,5,3]return = [9,7,5,3]

The array is strictly decreasing, so every value is greater than all values to its right.

Example 3

nums = [7,7,3]return = [7,3]

The first 7 is not strictly greater than the equal 7 to its right. The second 7 and the final value 3 are leaders.

Constraints

  • 1 <= nums.length <= 10^5
  • -10^9 <= nums[i] <= 10^9

More Accenture problems

  • Alternating Index Square SumONSITE INTERVIEW · Seen Sep 2026
  • Nearest Composite NumberOA · Seen Sep 2026
  • Minimum Password IncrementsOA · Seen Sep 2026
All Accenture interview questionsSee Accenture hiring insights
Saved
public int[] findLeaders(int[] nums) {
  // Write your code here.
}
Checking account…