## HackerEarth Interview Question for Problem Setters

Country: India
Interview Type: Written Test

Comment hidden because of low score. Click to expand.
0
of 0 vote

I think we can solve using dp.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Basically this is a DP problem. g counts palindromes, f counts special palindromes..

``````N = 3
K = 3
g = [1,K] + [0]*(N-1)
f = [1,K] + [0]*(N-1)

for i in range(2,N+1):
z = (i+1)//2
g[i] = K*g[i-2]
f[i] = g[i]
for j in range(2,z+1):
f[i] -= f[j] * g[max(0, i-2*j)]
print (f[N])``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````N = 3
K = 3
g = [1,K] + [0]*(N-1)
f = [1,K] + [0]*(N-1)

for i in range(2,N+1):
z = (i+1)//2
g[i] = K*g[i-2]
f[i] = g[i]
for j in range(2,z+1):
f[i] -= f[j] * g[max(0, i-2*j)]
print (f[N])``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.