Introduction
This challenge is to find the palindromic words from sentence(s). Palindrome is a word reading the same backward as forward. While finding the palindromic words from the sentence(s), the noise words should be removed if any is present in the sentence. There is a table "Noise" that defines Noise words
For e.g. MADAM is a palindrome but MADAM! is not. So we need to first remove noise character "!" from MADAM!
There are 2 tables in challenge. One contains the data from which we need to find the Palindromes and another contains noise words.
Sample Data
Table - Sentence
ID Sentence
-- -------------------------------
1 Hello Madam! how are you Madam?
2 She peep through the window
3 This is without any Palindrome
Table - Noise
ID Noise
-- -----
1 ?
2 !
Expected Results
ID Sentence PalindromeFound PalandromicWords FoundAt
-- ------------------------------- --------------- ---------------- -------------
1 Hello Madam! how are you Madam? 2 Madam Position : 2,6
2 She peep through the window 1 peep Position : 2
3 This is without any Palindrome 0 NULL NULL
Rules
- ID should be sorted in Ascending Order.
- The program should run in SQL SERVER 2005 and above.
- If no palindrome found in the sentence, then PalindromeFound column will be 0,PalandromicWords
and FoundAt column will be NULL.
- The output should be in the same way as it has been shown. Column names should be
exactly the same and the result must be sorted in Ascending order of ID.
Sample Script
Use the following script to generate the sample data.
DECLARE @Sentence TABLE(ID INT IDENTITY, Sentence VARCHAR(1000))
INSERT INTO @Sentence(Sentence)
SELECT 'Hello Madam! how are you Madam?' UNION ALL
SELECT 'She peep through the window' UNION ALL
SELECT 'This is without any Palindrome'
SELECT * FROM @Sentence
DECLARE @Noise TABLE(ID INT IDENTITY, Noise VARCHAR(10))
INSERT INTO @Noise(Noise)
SELECT '?' UNION ALL
SELECT '!'
SELECT * FROM @Noise
Restrictions
- The solution should be a single query that starts with a "SELECT" or “;WITH”.
Notes
Tags:Puzzles, TSQL Beginners Challenge, TC, TSQL Beginners Challenge 16