Ask.com Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

class PageRedirect
{
private :

const int p2_page_max_limit;
int p2_page_redirected_count;

const int p3_page_max_limit;
int p3_page_redirected_count;

const int p4_page_max_limit;
int p4_page_redirected_count;

const int p5_page_max_limit;
int p5_page_redirected_count;

static int redirectedOrderCount;

public :

PageRedirect() : p2_page_max_limit(10), p3_page_max_limit(5), p4_page_max_limit(20), p5_page_max_limit(65)
{
p2_page_redirected_count = 0;
p3_page_redirected_count = 0;
p4_page_redirected_count = 0;
p5_page_redirected_count = 0;

PageRedirect::redirectedOrderCount = 2; //2 - redirect to p2, 3 - redirect to p3, 4 - redirect to p4, 4 - redirect to p4
}

void RedirectFromP1()
{
if (PageRedirect::redirectedOrderCount == 2)
{
if (p2_page_redirected_count < p2_page_max_limit)
{
p2_page_redirected_count = p2_page_redirected_count + 1;

//Redirect to p2

}

PageRedirect::redirectedOrderCount = PageRedirect::redirectedOrderCount + 1;
}

if (PageRedirect::redirectedOrderCount == 3)
{
if (p3_page_redirected_count < p3_page_max_limit)
{
p3_page_redirected_count = p3_page_redirected_count + 1;

//Redirect to p3
}

PageRedirect::redirectedOrderCount = PageRedirect::redirectedOrderCount + 1;
}

if (PageRedirect::redirectedOrderCount == 4)
{
if (p4_page_redirected_count < p4_page_max_limit)
{
p4_page_redirected_count = p4_page_redirected_count + 1;

//Redirect to p4
}

PageRedirect::redirectedOrderCount = PageRedirect::redirectedOrderCount + 1;
}

if (PageRedirect::redirectedOrderCount == 5)
{
if (p5_page_redirected_count < p5_page_max_limit)
{
p5_page_redirected_count = p5_page_redirected_count + 1;

//Redirect to p5
}

PageRedirect::redirectedOrderCount = PageRedirect::redirectedOrderCount + 1;
}

if (PageRedirect::redirectedOrderCount > 5)
{
PageRedirect::redirectedOrderCount = 2;
}

if ((p2_page_redirected_count + p3_page_redirected_count + p4_page_redirected_count + p5_page_redirected_count) == 100)
{
p2_page_redirected_count = 0;
p3_page_redirected_count = 0;
p4_page_redirected_count = 0;
p5_page_redirected_count = 0;
}
}
};

The above code will redirect to the pages in round robin fashion. p2->p3->p4->p5->p2->.. so on until they reach the limit.

Is this correct implementation? Any other better way to do?

- Anonymous January 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Looks good. I think random number generation more appropriate. Say if rand() returns a floating point numbers between 0.0 to 1.0, if (0.1 <= value < 0.15) we redirect to p3.html and so on. In your case, there will be a situation when user will refresh p1.html 65 times before he skips p5.html.

- jatin085 April 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//Calculate a random number between 0-99;
var random = Math.floor(Math.random()*100);

if(random >= 0 && random < 10) {
  //redirect to p2.html
}
else if(random >= 10 && random < 15) {
  //redirect to p3.html
}
else if(random >= 15 && random < 35) {
  //redirect to p4.html
}
else {
  //redirect to p5.html
}

- Anonymous August 28, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More