This challenge invites you to identify the longest sequence of alphabets from a string.
This challenge is Version 2 of the TSQL Challenge 67. The difference is that in this version, you should apply circling while finding the longest sequence.
That means in string "XYZABCGDS", "XYZABC" is the longest sequence of alphabets.
A cycle can repeat itself many times. Thus you could have "XYZABCDEFGHIJKLMNOPQRSTUVWXYZABCD" as input data.
Database Source Control in just 5 minutes
It takes just 5 minutes to connect your SQL databases to source control. Got 5 minutes to spare?
Bring your database development process forward by 5 years.
Get started now.
Sample Data
ID String
-- ---------------------------
1 ASDFKIJKLMNAXDBABCIJKPPSRNK
2 XYZABCPPCKLMIDB *)(3 xxABC
3 ASDF;LKJQWERPOIUNMLKSTUVABC
Expected Results
ID Sequence
-- --------
1 IJKLMN
2 XYZABC
3 STUV
Rules
- The database has a case-insensitive collation.
- Only the 26 letters from A to Z are to be considered in a sequence.
- Input string can contain special characters.
- Input string will contain atleast 1 letter from A to Z.
- If more than one sequence having same number of characters is found, then the sequence that begins earlier in the English alphabet should get precedence.
- The output should be ordered by ID.
- The number of cycles is limited only by the length of a varchar(max) column.
Sample Script
Use the TSQL Script given below to generate the source tables and fill them with sample data.
IF OBJECT_ID('TC70','U') IS NOT NULL BEGIN
DROP TABLE TC70
END
GO
CREATE TABLE TC70(
ID INT IDENTITY,
String VARCHAR(MAX)
)
GO
INSERT INTO TC70(String)
SELECT 'ASDFKIJKLMNAXDBABCIJKPPSRNK' UNION ALL
SELECT 'XYZABCPPCKLMIDB *)(3 xxABC' UNION ALL
SELECT 'ASDF;LKJQWERPOIUNMLKSTUVABC'
SELECT * FROM TC70
GO
Restrictions
- The solution should be a single query that starts with a "SELECT" or “;WITH”
Notes
- Read the Submission Guidelines and make sure that your solution follows them.
- If you would like to use a Tally Table, you can use the script given here. Your solution should not include the script to create and populate the tally table. You can assume that the tally table will be available in the database where the evaluation team will run your Code.
Database Source Control in just 5 minutes
It takes just 5 minutes to connect your SQL databases to source control. Got 5 minutes to spare?
Bring your database development process forward by 5 years.
Get started now.