Find leader in array in c#
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
JohnRank #2,322 · 608 reputationPosted Nov 17, 2016, 12:08 AM EST
voidprintLeaders(intarr[],intsize){for(inti = 0; i < size; i++){intj;for(j = i+1; j < size; j++){if(arr[i] <= arr[j])break;}if(j == size)// the loop didn't breakconsole.write arr[i];}}MayankRank #4,018 · 371 reputationPosted Nov 17, 2016, 12:42 AM EST
using namespace std;
/*C++ Function to print leaders in an array */
void printLeaders(int arr[], int size)
{
for (int i = 0; i < size; i++)
{
int j;
for (j = i+1; j < size; j++)
{
if (arr[i] <= arr[j])
break;
}
if (j == size) // the loop didn't break
cout << arr[i] << " ";
}
}
/* Driver program to test above function */
int main()
{
int arr[] = {16, 17, 4, 3, 5, 2};
int n = sizeof(arr)/sizeof(arr[0]);
printLeaders(arr, n);
return 0;
}
I u think it resolve your query please mark as answer.
Brijesh RathorRank #7,391 · 242 reputationPosted Nov 17, 2016, 12:50 AM EST