# Help with Contest problem

## Recommended Posts

afroboy    122
Heres the problem Calculate the number of table arrangement so that any two cows sitting next to each other dont differ in height by no more than K inches. so for: 4 10 2 16 6 10 There are 4 cows, with heights 2, 16, 6, and 10. Two cows whose heights differ by more than 10 do not want to sit next to each other. Can anyone just give me some hints, i am completely stuck

##### Share on other sites
ukdeveloper    264
What are you after, code or just some help on abstracting and solving the problem?

I'd say some kind of comparison needs to be made - if you've got an array of cows within your program, element[i] and element[i+1] cannot differ by >10.

Consequently, if difference between Cow A and Cow B <=10, they can sit in adjacent array indices. However, if you're trying to sort it into order i.e. cow with height 1 at position [0], cow with height 4 at [1], cow at height 7 at [2], cow with height 19 not at position [3] because of our difference of 10 rule... then that's another story. That, in my mind, could wind up being quite complicated.

Not sure if I should be helping, actually - is this a contest like you say, or is this homework? We're not supposed to help with homework. I don't know if it's forum policy, but it's frowned upon.

##### Share on other sites
JohnBolton    1372
I would help you in this contest but I already gave the answers to all of the questions to one of your competitors because I want him to win. Sorry.

##### Share on other sites
thedustbustr    191
if runtime efficiency isn't a problem, build a search tree and search it.