consider a permutation of first 'N' natural numbers 'good' if it doesn't have 'x' and 'x+1' appearing consecutively,
where (1 <= x <= N).
for example, for N=3, all 'good' permutations are:
1. {1,3,2}
2. {2,1,3}
3. {3,2,1}
Write a java program that takes an input 'N' and displays the number of possible 'good' permutations. So, for input
of 3 for 'n' above, we would print '3' as the output.

ashok mandala wrote:hi frnds i need help for the below problem

consider a permutation of first 'N' natural numbers 'good' if it doesn't have 'x' and 'x+1' appearing consecutively,
where (1 <= x <= N).
for example, for N=3, all 'good' permutations are:
1. {1,3,2}
2. {2,1,3}
3. {3,2,1}
Write a java program that takes an input 'N' and displays the number of possible 'good' permutations. So, for input
of 3 for 'n' above, we would print '3' as the output.

why not {2,3,1} is good permutation?

~Suresh

ashok mandala
Greenhorn

Joined: Nov 23, 2012
Posts: 9

posted

0

we are considering that the permutation will be good if it doesn't have consecutive numbers........

Read Suresh Sajja’s post carefully; it contains good advice. I would suggest you filter each permutation before adding it to your list, however.
Please don’t use {} around your numbers, because that denotes a set. Use [] for a sequence. So [1, 2, 3] is a “bad” sequence and [3, 2, 1] is a “good” sequence.

ashok mandala
Greenhorn

Joined: Nov 23, 2012
Posts: 9

posted

0

i got the logic for first step...
but dont know how to filter.....
help me out..........

according to this question a good permutation is,that doesn't have consecutive increasing numbers side by side...
for input 3 we can only have {[1,3,2],[3,1,2],[2,1,3],[3,2,1]} but we cant have {[1,2,3],[2,3,1],[]} i.e we can't have x,x+1 type arrangements....