Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Circular Racecourse Puzzle

39 views
Skip to first unread message

sergei.na...@gmail.com

unread,
Apr 15, 2015, 8:09:17 PM4/15/15
to
Along a circular racecourse are N pits, clockwise numbered from 0 through N -1. The amount of petrol available at pit i equals p[i], whereas the amount of petrol needed to travel from pit i to the clockwise next pit equals q[i]. Write a program to determine all pits from which a car, with an initially empty and sufficiently large tank, can start and complete the whole course in clockwise direction.

The complete description of the problem (along with sample solution) is given at : https://www.dropbox.com/s/pvyd1qnarg05pdh/circular_racecourse.pdf?dl=0

This problem is from my book "Cracking Programming Interviews: 500 Questions with Solutions", and I am trying to improve the solution of this problem.

Kindly let me know your inputs.

Thanks,
Sergei

Öö Tiib

unread,
Apr 16, 2015, 9:48:38 AM4/16/15
to
On Thursday, 16 April 2015 03:09:17 UTC+3, sergei.na...@gmail.com wrote:
> Along a circular racecourse are N pits, clockwise numbered from 0
> through N -1. The amount of petrol available at pit i equals p[i],
> whereas the amount of petrol needed to travel from pit i to the
> clockwise next pit equals q[i]. Write a program to determine all
> pits from which a car, with an initially empty and sufficiently
> large tank, can start and complete the whole course in clockwise
> direction.
>
> The complete description of the problem (along with sample solution)
> is given at : https://www.dropbox.com/s/pvyd1qnarg05pdh/circular_racecourse.pdf?dl=0
>
> This problem is from my book "Cracking Programming Interviews:
> 500 Questions with Solutions", and I am trying to improve the

Looking at the pseudocode in the snippet that you drop-boxed it
is a bad book. Throw it away.

I dislike code that uses numeric literal 1 and names l and I in
mix. I value readability over efficiency. The few places that
deserve fixing because of efficiency are always lot easier to
fix in readable code.

> solution of this problem.

Are the 'N', 'p[N]' and/or 'q[N]' compile-time or run-time values?
Have you achieved implementation of described solution in C++?
If no, what does hold you back? Can you post what you have
achieved? In what direction you try to improve it? What you have
done or plan to do to improve it?

> Kindly let me know your inputs.

Inputs to where?
0 new messages