in Others edited by
122 views
0 votes
0 votes

A palindrome is a string that reads the same in reverse (e.g. ABBA or KAYAK or MALAYALAM).
How many strings of length 5 using the letters from $\{A, B, C, D, E\}$ have no palindromic substring of length at least 2?

  1. $243$
  2. $405$
  3. $540$
  4. $675$
  5. $1280$

     

in Others edited by
by
122 views

1 Answer

1 vote
1 vote

for a string $s$ , notice that for any index $i$ the following cases

  1. if $s[i] = s[i+1]$, then we will have a palindromic substring of length 2 . so 2 adjacent characters have to be different always
  2. if $s[i] = s[i+2]$, then we will have a palindromic substring of length 3 . so 3 adjacent characters have to be different always because $i,i+1$ form the 1st case and $i,i+2$ form the 2nd case

so using this we get our base case , $f(3) = \text{select 3 diff characters and permute them} = \binom{5}{3}\times3!$

$\small{f(n) = (\text{nth char we add should be } s[n] \neq s[n-1] \neq s[n-2] \text{ from 1,2} ) = \text{3 choices for nth char} = f(n-1)\cdot3}$

$f(5) = f(4)\times3 = f(3) \times 3 \times 3 = \binom{5}{3}\times3!\times 3 \times 3 = 540$

so ans is C i.e. 540

edited by
Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

64.3k questions

77.9k answers

244k comments

80.0k users