Algorithm for redirecting the traffic

Posted by TechGeeky on Stack Overflow See other posts from Stack Overflow or by TechGeeky
Published on 2012-11-16T22:48:23Z Indexed on 2012/11/16 23:00 UTC
Read the original article Hit count: 251

Filed under:
|

I was going through the interview questions and found out the below question which I am not able to answer it. Can anyone provide some sort of algorithm for this problem how can I solve it?

  1. There are a cluster of stateless servers all serving the same pages.
  2. The servers are hosting 5 web pages- p1.html, p2.html, p3.html, p4.html and p5.html
  3. p1.html just redirects users to the other 4 pages
  4. Requests to p1.html should result in 10% of users being redirected to p2.html, 5% of users redirected to p3.html, 20% of users redirected to p4.html, and 65% of users redirected to p5.html.
  5. Users do not need to stick to the page they are first redirected to. They could end up on a different page with every request to p1.html
  6. Write a function/pseudocode that would be invoked with every request to p1.html and redirect the correct percentage of users to the correct page.

Any suggestions will be of great help.

© Stack Overflow or respective owner

Related posts about java

Related posts about algorithm