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 3278152
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:26:58+00:00 2026-05-17T19:26:58+00:00

One of my former students sent me a message about this interview question he

  • 0

One of my former students sent me a message about this interview question he got while applying for a job as a Junior Developer.

There are two candidates running for president in a mock classroom election. Given the two percentages of voters, find out the least amount of possible voters in the classroom.

Examples:

Input: 50.00,50.00
Output: 2

Input: 25.00,75.00
Output: 4

Input: 53.23, 46.77
Output: 124 // The first value, 1138 was wrong. Thanks to Loïc for the correct value

Note: The sum of the input percentages are always 100.00%, two decimal places

The last example got me scratching my head. It was the first time I heard about this problem, and I’m kindof stumped on how to solve this.

EDIT: I called my student about the problem, and told me that he was not sure about the last value. He said, and I quote, "It was an absurdly large number output" 🙁 sorry! I should’ve researched more before posting it online~ I’m guessing 9,797 is the output on the last example though..

  • 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-17T19:26:58+00:00Added an answer on May 17, 2026 at 7:26 pm

    You can compute these values by using the best rational approximations of the voter percentages. Wikipedia describes how to obtain these values from the continued fraction (which can be computed these using the euclidean algorithm). The desired result is the first approximation which is within 0.005% of the expected value.

    Here’s an example with 53.23%:

    10000 = 1 * 5323 + 4677
    5323  = 1 * 4677 + 646
    4677  = 7 * 646  + 155
    646   = 4 * 155  + 26
    155   = 5 * 26   + 25
    26    = 1 * 25   + 1
    25    = 25* 1    + 0
    
    Approximations:
    1:   1 / 1
     -> 1 = 100%
    2:   1 / (1 + 1/1) 
     -> 1/2 = 50%
    2.5: 1 / (1 + 1 / (1 + 1/6))
     -> 7/1 = 53.75%
    3:   1 / (1 + 1 / (1 + 1/7))
     -> 8/15 = 53.33%
    3.5: 1 / (1 + 1 / (1 + 1 / (7 + 1/3)))
     -> 25/47 = 53.19%
    4:   1 / (1 + 1 / (1 + 1 / (7 + 1/4)))
     -> 33/62 = 53.23%
    

    The reason we have extra values before the 3rd and 4th convergents is that their last terms (7 and 4 respectively) are greater than 1, so we must test the approximation with the last term decremented.

    The desired result is the denominator of the first value which rounds to the desired value, which in this vase is 62.

    Sample Ruby implementation available here (using the formulae from the Wikipedia page here, so it looks slightly different to the above example).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can one get records with highest/smallest per group? Former title of this question
one question about PHP Development. I am building up some Form Fields for Calculations.
This one is similar to a question that I asked yesterday. However my concern
Please compare these two codes. I can't understand why former one didn't work while
one question about NDBCLUSTER. I inherited the writing of a web site basing on
I have got a question about the order in IEnumerable . As far as
I got two divs, one is a background and the other is the container
This one's perhaps a duplicate of variable not recognized inside contentscript under the same
A former colleague of mine started a discussion half an hour ago about JavaBeans,
This question is based on my plan at the thread . The following figure

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.