Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5964219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:23:30+00:00 2026-05-22T19:23:30+00:00

Possible Duplicate: Finding the second highest number in array I have this, for(int i=0;i<Dices.length;i++){

  • 0

Possible Duplicate:
Finding the second highest number in array

I have this,

       for(int i=0;i<Dices.length;i++){
        if( Dices[i].getValue() > highest ){
            highest = Dices[i].getValue();
        }
       }

to get highest value. I now want to get the second highest, how can I do it? Cant i take advantage of this highest variable for getting the second highest?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:23:31+00:00Added an answer on May 22, 2026 at 7:23 pm

    How about something like this in O(n) speed:

    // first, second, d0, d1, di all typed by whatever getValue() returns...
    // This assumes you have at least two elements in your Dices array
    
    d0 = Dices[0].getValue();
    d1 = Dices[1].getValue();
    if (d0 > d1) {
        first=d0;
        second=d1;
    } else {
        first=d1;
        second=d0;
    }
    
    for (int i = 2; i < Dices.length; i++) {
        di = Dices[i].getValue();
        if (di > first) {
            second = first;
            first = di;
        } else if (di > second)
            second = di;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Finding an enum value by its Description Attribute I have a generic
Possible Duplicate: Finding a single number in a list Given an array of numbers,
Possible Duplicate: array_splice() for associative arrays How to add an array value to the
Possible Duplicate: PHP get all arguments as array? Within a javascript function arguments always
Possible Duplicate: Finding all cycles in graph I have a task I've been wrapping
Possible Duplicate: Finding a submatrix with the maximum possible sum in O(n^2) I have
Possible Duplicate: Finding the N th Occurrence of a Match line I have multi-line
Possible Duplicate: Finding Variable Type in JavaScript How can I test if a value
Possible Duplicate: Finding the Variable Name passed to a Function in C# In C#,
Possible Duplicates: Finding duplicate files and removing them. In Python, is there a concise

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.