Only one alphabet can be removed from Words list and it should become a palindrome. List the palindrome word so generated. If no answer is possible, answer will be blank. Ex. kayaks – Remove s and resultant palindrome word is kayak. raqdapr – No palindrome can be generated out of this. Hence, answer is blank.
📌 Challenge Details and Links
ExcelBI Excel Challenge Number: 699
Challenge Difficulty: ⭐️⭐️
📥Download Sample File
📥Link to the solutions on LinkedIn
Solving the challenge of Remove One Letter Palindrome with Power Query
Power Query solution 1 for Remove One Letter Palindrome, proposed by Alejandro Simón 🇵🇦 🇪🇸:
let
a = [Words],
b = {0..Text.Length(a)-1},
c = List.Transform(b, each Text.RemoveRange(a,_,1)),
d = List.Select(c, each Text.Reverse(_)=_){0}?
in d)
in
Sol
Power Query solution 2 for Remove One Letter Palindrome, proposed by Ramiro Ayala Chávez:
let
S = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],
a = List.Transform(S[Words], Text.ToList),
Fx = (x) =>
let
b = List.Generate(
() => [i = 0],
each [i] < List.Count(x),
each [i = [i] + 1],
each List.RemoveRange(x, [i], 1)
),
c = List.Transform(b, Text.Combine),
d = List.Select(c, each Text.Reverse(_) = _){0}
in
d,
e = List.Transform(a, each try Fx(_) otherwise null),
Sol = Table.FromColumns({e}, {"Answer Expected"})
in
Sol
Power Query solution 3 for Remove One Letter Palindrome, proposed by Meganathan Elumalai:
let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],
Result = Table.AddColumn(
Source,
"Result",
(f) =>
Text.Combine(
List.Transform(
{0 .. Text.Length(f[Words]) - 1},
(x) =>
[
txt = Text.ReplaceRange(f[Words], x, 1, ""),
fin = if txt = Text.Reverse(txt) then txt else ""
][fin]
)
)
)
in
Result
Power Query solution 4 for Remove One Letter Palindrome, proposed by Antriksh Sharma:
let
Source = Table,
Ans = Table.AddColumn(
Source,
"Answer",
(x) =>
[
str = x[Words],
Pos = List.Positions(Text.ToList(str)),
T = List.Transform(Pos, each Text.ReplaceRange(str, _, 1, "")),
c = Text.Combine(List.Select(T, each _ = Text.Reverse(_)))
][c],
type text
)
in
Ans
Power Query solution 5 for Remove One Letter Palindrome, proposed by Mihai Radu O:
let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],
s = Table.TransformColumns(
Source,
{
"Words",
each [
l = Text.Length(_),
a = List.Transform({0 .. l - 1}, (x) => Text.RemoveRange(_, x, 1)),
b = try List.Select(a, (x) => Text.Reverse(x) = x){0} otherwise null
][b]
}
)
in
s
Power Query solution 6 for Remove One Letter Palindrome, proposed by Maciej Kopczyński:
let
A = Excel.CurrentWorkbook(){[Name = "tblStart"]}[Content],
B = Table.TransformColumns(
A,
{
{
"Words",
each List.Select(
List.Accumulate(
List.Numbers(0, Text.Length(_)),
{},
(state, curr) => state & {Text.RemoveRange(_, curr, 1)}
),
each _ = Text.Reverse(_)
)
}
}
),
C = Table.RenameColumns(Table.ExpandListColumn(B, "Words"), {{"Words", "Answer Expected"}})
in
C
Power Query solution 7 for Remove One Letter Palindrome, proposed by Aleksandar Kovacevic:
let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],
Fx = each [
a = List.Positions(Text.ToList(_)),
b = List.Transform(a, (x) => Text.ReplaceRange(_, x, 1, "")),
c = List.Select(b, each _ = Text.Reverse(_)),
d = if List.IsEmpty(c) then {null} else c
][d],
Res = Table.FromRows(List.Transform(Source[Words], Fx), {"Answer Expected"})
in
Res
Power Query solution 8 for Remove One Letter Palindrome, proposed by Oleksandr Mynka:
let
src = Excel.CurrentWorkbook(){[Name = "SourceTable"]}[Content],
fx = (txt) =>
[
ar = List.Buffer(Text.ToList(txt)),
tr = List.Transform(
ar,
(x) =>
[
str = List.RemoveMatchingItems(ar, {x}),
rev = List.Reverse(str),
out =
if (str = rev and List.Count(str) + 1 = List.Count(ar)) then
Text.Combine(str)
else
null
][out]
),
cmb = Text.Combine(List.RemoveNulls(tr))
][cmb],
res = Table.TransformColumns(src, {"Words", fx})
in
res
Solving the challenge of Remove One Letter Palindrome with Excel
Excel solution 1 for Remove One Letter Palindrome, proposed by Rick Rothstein:
=MAP(
A2:A10,
LAMBDA(
z,
REDUCE(
"",
SEQUENCE(
LEN(
z
)
),
LAMBDA(
a,
x,
LET(
w,
LEFT(
z,
x-1
)&MID(
z,
x+1,
99
),
n,
LEN(
w
),
IF(
w=CONCAT(
MID(
w,
SEQUENCE(
n,
,
n,
-1
),
1
)
),
w,
a
)
)
)
)
)
)
Excel solution 2 for Remove One Letter Palindrome, proposed by 🇰🇷 Taeyong Shin:
=MAP(A2:A10,LAMBDA(x,CONCAT(REGEXEXTRACT(SUBSTITUTE(x,REGEXEXTRACT(x,".|$",1),,1),"^((.)(?1)2|.?)$|$"))))
=BYROW(MAP(REPLACE(A2:A10,SEQUENCE(,20),1,),LAMBDA(x,REPT(x,CONCAT(MID(x,LEN(x)-SEQUENCE(LEN(x))+1,1))=x))),CONCAT)
Excel solution 3 for Remove One Letter Palindrome, proposed by Kris Jaganah:
=MAP(A2:A10,
LAMBDA(v,
LET(a,
LEN(
v
),
b,
SEQUENCE(
a
),
c,
MID(
v,
b,
1
),
d,
MAP(
c,
LAMBDA(
x,
SUM(
N(
x=c
)
)
)
),
e,
FILTER(c,
(b=INT((a/2)+0.5))+(d>1)),
f,
IF(
ROWS(
e
)=a-1,
SORTBY(
e,
-DROP(
b,
-1
)
),
0
),
IF(
MIN(
N(
e=f
)
),
CONCAT(
f
),
""
))))
Excel solution 4 for Remove One Letter Palindrome, proposed by Julian Poeltl:
=MAP(A2:A10,LAMBDA(W,LET(R,SUBSTITUTE(W,CHAR(SEQUENCE(26,,97)),""),XLOOKUP(1,--MAP(R,LAMBDA(A,LET(L,LEN(A),T,L/2,LEFT(A,T)=CONCAT(MID(A,SEQUENCE(T,,L,-1),1))))),R,"",,-1))))
Excel solution 5 for Remove One Letter Palindrome, proposed by Timothée BLIOT:
=MAP(A2:A10,LAMBDA(z,IFERROR(CONCAT(MAP(REPLACE(z,SEQUENCE(15),1,),LAMBDA(x,IF(CONCAT(MID(x,16-SEQUENCE(15),1))=x,x,"")))),"")))
Excel solution 6 for Remove One Letter Palindrome, proposed by Duy Tùng:
=MAP(A2:A10,LAMBDA(x,LET(v,LEN(x),TEXTJOIN(", ",,MAP(REPLACE(x,SEQUENCE(v),1,),LAMBDA(s,REPT(s,s=CONCAT(MID(s,v-SEQUENCE(v-1),1)))))))))
Excel solution 7 for Remove One Letter Palindrome, proposed by Sunny Baggu:
=MAP(
A2:A10,
LAMBDA(w,
LET(
_s1, SEQUENCE(LEN(w)),
_s2, SORT(_s1, , -1),
_a, DROP(
REDUCE("", _s1, LAMBDA(a, v, VSTACK(a, REPLACE(w, v, 1, "")))),
1
),
_b, MAP(
_a,
LAMBDA(t,
CONCAT(MID(t, DROP(_s1, -1), 1)) =
CONCAT(MID(t, DROP(_s2, 1), 1))
)
),
FILTER(_a, _b, "")
)
)
)
Excel solution 8 for Remove One Letter Palindrome, proposed by Md. Zohurul Islam:
=LET(
z,
A2:A10,
MAP(
z,
LAMBDA(
y,
LET(
sq,
SEQUENCE(
LEN(
y
)
),
u,
MAP(
sq,
LAMBDA(
x,
LET(
a,
LEFT(
y,
x-1
),
b,
MID(
y,
x+1,
MAX(
LEN(
z
)
)
),
d,
a&b,
e,
LEN(
d
),
f,
CONCAT(
MID(
d,
SEQUENCE(
,
e,
e,
-1
),
1
)
),
FILTER(
f,
ISNUMBER(
XMATCH(
d,
f
)
),
""
)
)
)
),
v,
CONCAT(
u
),
v
)
)
)
)
Excel solution 9 for Remove One Letter Palindrome, proposed by Asheesh Pahwa:
=REDUCE(B1,A2:A10,LAMBDA(x,y,VSTACK(x,LET(l,LEN(y),s,SEQUENCE(l),m,MAP(s,LAMBDA(a,LET(r,REPLACE(y,a,1,""),_m,MAP(r,LAMBDA(p,CONCAT(MID(p,SEQUENCE(LEN(p),,LEN(p),-1),1)))),FILTER(r,r=_m,"")))),CONCAT(m)))))
Excel solution 10 for Remove One Letter Palindrome, proposed by Meganathan Elumalai:
=MAP(
A2:A10,
LAMBDA(
a,
CONCAT(
MAP(
SEQUENCE(
LEN(
a
)
),
LAMBDA(
x,
LET(
y,
REPLACE(
a,
x,
1,
),
REPT(
y,
y=CONCAT(
MID(
y,
SEQUENCE(
LEN(
y
),
,
LEN(
y
),
-1
),
1
)
)
)
)
)
)
)
)
)
Excel solution 11 for Remove One Letter Palindrome, proposed by Antriksh Sharma:
=LET(Words, A2:A10, Acc, REDUCE("", Words, LAMBDA(s1_, c1_, LET(i, REDUCE("", SEQUENCE(LEN(c1_)), LAMBDA(s2_, c2_, LET(b, REPLACE(c1_, c2_, 1, ""), c, TEXTJOIN("", 1, MID(b, SORT(SEQUENCE(LEN(c1_)), 1, -1), 1)), d, VSTACK(s2_, HSTACK(b, c)), d))), j, DROP(i, 1), k, FILTER(CHOOSECOLS(j, 1), CHOOSECOLS(j, 1) = CHOOSECOLS(j, 2), ""), l, VSTACK(s1_, k), l))), DROP(Acc, 1))
Excel solution 12 for Remove One Letter Palindrome, proposed by Erdit Qendro:
=MAP(
A2:A10,
LAMBDA(
a,
LET(
st,
a,
sq,
SEQUENCE(
LEN(
st
)
),
rg,
REGEXREPLACE(
st,
".",
"",
sq
),
chk,
MAP(
rg,
LAMBDA(
r,
LET(
rx,
SEQUENCE(
LEN(
r
)
),
txR,
MID(
r,
rx,
1
),
IF(
TAKE(
txR,
1
)=TAKE(
txR,
-1
),
CONCAT(
SORTBY(
txR,
rx
)
)=CONCAT(
SORTBY(
txR,
-rx
)
)
)
)
)
),
FILTER(
rg,
chk,
""
)
)
)
)
Excel solution 13 for Remove One Letter Palindrome, proposed by Fredson Alves Pinho:
=MAP(
A2:A10,
LAMBDA(
x,
REDUCE(
"",
SEQUENCE(
LEN(
x
)
),
LAMBDA(
a,
v,
LET(
i,
REPLACE(
x,
v,
1,
""
),
s,
SEQUENCE(
LEN(
i
)
),
y,
MID(
i,
s,
1
),
IF(
i=CONCAT(
CHOOSEROWS(
y,
-s
)
),
i,
a
)
)
)
)
)
)
Excel solution 14 for Remove One Letter Palindrome, proposed by Craig Runciman:
=LET(x,
INDEX,
q,
SEQUENCE,
fn,
LAMBDA(t,
--(MID(
t,
q(
,
LEN(
t
)
),
1
)=MID(
t,
q(
,
LEN(
t
),
LEN(
t
),
-1
),
1
))),
DROP(
REDUCE(
"",
A2:A10,
LAMBDA(
a,
v,
LET(
l,
XMATCH(
0,
fn(
v
)
),
s,
SUBSTITUTE(
v,
IF(
OR(
ISEVEN(
l
),
ISEVEN(
LEN(
v
)
)
),
x(
MID(
v,
q(
,
LEN(
v
),
LEN(
v
),
-1
),
1
),
,
l
),
x(
MID(
v,
q(
,
LEN(
v
)
),
1
),
,
l
)
),
"",
1
),
t,
PRODUCT(
fn(
s
)
),
VSTACK(
a,
IF(
t,
s,
""
)
)
)
)
),
1
))
Excel solution 15 for Remove One Letter Palindrome, proposed by Cuong Pham:
=BYROW(A2:A10,LAMBDA(x,LET(a,REPLACE(x,SEQUENCE(LEN(x)),1,""),IFERROR(FILTER(a,REGEXTEST(a,"^((.)(?1)2|.?)$")=TRUE),""))))
Solving the challenge of Remove One Letter Palindrome with Python
Python solution 1 for Remove One Letter Palindrome, proposed by Konrad Gryczan, PhD:
import pandas as pd
path = "699 Palindrome after one character removal.xlsx"
input = pd.read_excel(path, usecols="A", nrows=10, names=["Words"])
test = pd.read_excel(path, usecols="B", nrows=10, names=["Answer Expected"]).fillna("")
def is_palindrome(word):
result = input["Words"].apply(
lambda word: next((word[:i] + word[i+1:] for i in range(len(word)) if is_palindrome(word[:i] + word[i+1:])), "")
)
print(result)
Solving the challenge of Remove One Letter Palindrome with Python in Excel
Python in Excel solution 1 for Remove One Letter Palindrome, proposed by Duy Tùng:
[', '.join({x for i in range(len(v)) if (x:=v[:i]+v[i+1:])==x[::-1]}) for v in xl("A2:A10")[0]]
Solving the challenge of Remove One Letter Palindrome with R
R solution 1 for Remove One Letter Palindrome, proposed by Konrad Gryczan, PhD:
library(tidyverse)
library(readxl)
path = "Excel/699 Palindrome after one character removal.xlsx"
input = read_excel(path, range = "A1:A10")
test = read_excel(path, range = "B1:B10") %>%
replace_na(list(`Answer Expected` = ""))
remove_each_char <- function(word) {
map_chr(
seq_len(nchar(word)),
(i) paste0(substr(word, 1, i - 1), substr(word, i + 1, nchar(word)))
)
}
is_palindrome = function(word) {
}
result = input %>%
unnest_longer(words) %>%
mutate(is_palindrome = map_lgl(words, is_palindrome)) %>%
filter(is_palindrome) %>%
select(-is_palindrome)
result2 = input %>%
left_join(result, by = c("Words" = "Words")) %>%
&&
