Here is the problem statement and what I gather is the array to the right of any has to be less then or equal to the leader. In the example and in the test inputs it seems not to account for larger sums. Another Example is the input 17 4 3 5 2 4 still states the 17 is a leader when 4+3+5+2+4=18 which would be greater than making 17 no longer a leader. I'm just trying to understand what it's asking for in this practice problem.

You are given an array arr of positive integers. Your task is to find all the leaders in the array. An element is considered a leader if it is greater than or equal to all elements to its right. The rightmost element is always a leader.

Examples:

Input: arr = [16, 17, 4, 3, 5, 2]
Output: [17, 5, 2]

Explanation: Note that there is nothing greater on the right side of 17, 5 and, 2.

Input: arr = [10, 4, 2, 4, 1]
Output: [10, 4, 4, 1]

Explanation: Note that both of the 4s are in output, as to be a leader an equal element is also allowed on the right. side

6 Replies 6

The requirement is to be greater than each of the numbers to the right individually, not greater than the sum of the numbers to the right.

Are you referring to this problem?

I think you might be misunderstanding the statement. You don’t need to sum anything; instead, you should compare each element with every element to its right, and if the number is greater than all the elements to its right, then it is a leader number.

Example:

17 is a leader number because 17 > 4, 3, 5, 2.

4 is not a leader number because, although 4 > 3 and 2, it is less than 5.

Thank you for the break-down as I was reading into the word 'all' when it would be better explained with 'each' as the all was presumptuous to summation. Thanks again @kitt51.

"all" doesn't imply or mean "sum". You have a misconception of what "all" means & how it is used.

Using "all elements" here is the normal way to express the requirement. So is "the elements".

Using "every element" is also idoimatic.

Using "any element" is not idiomatic but can be understood.

Using "each element" is not idiomatic but can be understood.

the array to the right of any has to be less then or equal to the leader

The problem statement doesn't give a requirement for the array. It defines what "leader" means & it asks for the leaders.

Your sentence doesn't make sense. One part that doesn't make sense is "to the right of any". The sentence is so unclear I don't know what you are trying to say. Maybe you are trying to say, "for an element to be a leader, every element of the array to the right of it has to be less than or equal to it". But that's not what you wrote. Use enough words, phrases & sentences, including clear references to things, to clearly say what you mean.

Your Reply

By clicking “Post Your Reply”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.