# Problem solving as bridge building

I would be grateful if someone can provide me a feedback on the blog post I have written. It’s my first attempt at such.

Thank you.

If you ask me to solve this problem my logic will be very different and so I’m bit confused. Is it me having incorrect way of problem solving, or is it you trying to confuse me?

@snigo Yes I did mention on one slide that -Insert your insight here-. So that was for you, who came up with a different solution. Thank you for looking at it. Wanna tell me how you will solve this problem of palindrome which I took in example?

For each number and it’s index in array find all same numbers and their indexes, slice array between indexes and check if this slice equals to itself reversed:

``````const random = () => Math.ceil(Math.random() * 9));
const array = [...Array(100)].map(random);
const palindromes = [];

for (let i = 0; i < array.length - 1; i++) {
for (let j = array.length - 1; j > i; j--) {
if (array[i] === array[j]) {
const slice = array.slice(i, j + 1);
slice.join('') === slice.reverse().join('') && palindromes.push(slice.join(''));
}
}
}

console.log(array, palindromes);
``````

That’s seems correct (ignoring the trivial palindrome of length 1).

A funny input I tell you ->
[ 1, -1, 3, 3, -1, 1 ]
=>
[ ‘1-133-11’, ‘-133-1’, ‘33’ ]