Given N positions, the task is to count the total number of ways to place X and Y such that no two X are together.
Input: 3 Output: 5 XYX, YYX, YXY, XYY and YYY Input: 4 Output: 8 XYXY, XYYX, YXYX, YYYX, YYXY, YXYY, XYYY and YYYY
For N = 1, X and Y are 2 possible ways.
For N = 2, XY, YX and YY are the 3 possible ways.
For N = 3, XYX, YYX, YXY, XYY and YYY are 5 possible ways.
For N = 4, XYXY, XYYX, YXYX, YYYX, YYXY, YXYY, XYYY and YYYY are 8 possible ways.
On solving for values of N, a Fibonacci pattern series is observed.
Below is the iterative implementation of the above approach:
Total ways are: 34
Time Complexity: O(N)
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Ways to place 4 items in n^2 positions such that no row/column contains more than one
- Total ways of choosing X men and Y women from a total of M men and W women
- Total ways of selecting a group of X men from N men with or without including a particular man
- Ways to form an array having integers in given range such that total sum is divisible by 2
- Find the sum of digits of a number at even and odd places
- Check whether sum of digits at odd places of a number is divisible by K
- Primality test for the sum of digits at odd places of a number
- Check if product of digits of a number at even and odd places is equal
- Check whether product of digits at even places of a number is divisible by K
- Find the total number of composite factor for a given number
- Find the total Number of Digits in (N!)N
- Count total number of even sum sequences
- Count total number of digits from 1 to n
- Total number of divisors for a given number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.