Ashton and String
Ashton appeared for a job interview and is asked the following question. Arrange all the distinct substrings of a given string in lexicographical order and concatenate them. Print the kth character of the concatenated string. It is assured that given value of k will be valid i.e. there will be a kth character. Can you help Ashton out with this? Note We have distinct substrings here, i.e. if string is aa, it's distinct substrings are a and aa. Function Description Complete the ashtonS
View Solution →String Similarity
For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings "abc" and "abd" is 2, while the similarity of strings "aaa" and "aaab" is 3. Calculate the sum of similarities of a string S with each of it's suffixes. Input Format The first line contains the number of test cases t. Each of the next t lines contains a string to process, s. Constraints 1 <= t <= 10 1 <= |
View Solution →Super Functional Strings
We define a function, F, on a string, P , as follows: where: length(P) denotes the number of characters in string P. distinct(P) denotes the number of distinct characters in string P. Consuela loves creating string challenges and she needs your help testing her newest one! Given a string, S, consisting of N lowercase letters, compute the summation of function F (provided above) over all possible distinct substrings of S. As the result is quite large, print it modulo 10^9 + 7. Inpu
View Solution →Circular Palindromes
A palindrome is a string that reads the same from left to right as it does from right to left. Given a string, , S of N lowercase English letters, we define a k-length rotation as cutting the first kcharacters from the beginning of S and appending them to the end of S. For each S, there are N possible k-length rotations (where 0 <= K < N ). See the Explanation section for examples. Given N and S, find all N k-length rotations of S; for each rotated string, Sk, print the maximum p
View Solution →Substring Diff
In this problem, we'll use the term "longest common substring" loosely. It refers to substrings differing at some number or fewer characters when compared index by index. For example, 'abc' and 'adc' differ in one position, 'aab' and 'aba' differ in two. Given two strings and an integer k, determine the length of the longest common substrings of the two strings that differ in no more than k positions. For example, k=1. Strings s1=abcd and s2=bbca. Check to see if the whole string (the long
View Solution →