We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The x==1 condition is wrong since the possible ways to arrange when x==1 is maximum of all. So you can't return 1.
You are using combination it only select the value and even if you have used permutations it doesn't gives the repeated value permutations.
You have to use product from itertools but even after doing that it will give all results and hence you have to verify each array and then check if its 1st and last value are not equal to 1 or x and no consecutive numbers are same and decrease the count.
But since it takes to much memory and time will give runtime error.
Construct the Array
You are viewing a single comment's thread. Return to all comments →
I was wondering why can't i solve this using combinations from itertools? Anyone who can find flaws in this approach?
The x==1 condition is wrong since the possible ways to arrange when x==1 is maximum of all. So you can't return 1.
You are using combination it only select the value and even if you have used permutations it doesn't gives the repeated value permutations.
You have to use product from itertools but even after doing that it will give all results and hence you have to verify each array and then check if its 1st and last value are not equal to 1 or x and no consecutive numbers are same and decrease the count.
But since it takes to much memory and time will give runtime error.
adjacent elements cannot be same and elements can be repeated as well ..do check for these points