title-img


Two Strings Game

Consider the following game for two players: There are two strings A and B. Initially, some strings A' and B' are written on the sheet of paper. A' is always a substring of A and B' is always a substring of B. A move consists of appending a letter to exactly one of these strings: either to A' or to B'. After the move the constraint of A' being a substring of A and B' is a substring of B should still be satisfied. Players take their moves alternately. We call a pair (A', B') a position. Two

View Solution →

Letter Islands

You are given string s and number k. Consider a substring of string . For each position of string mark it if there is an occurence of the substring that covers the position. More formally, position will be marked if there exists such index that: and . We will tell produce islands if all the marked positions form groups of contiguous positions. For example, if we have a string ababaewabaq the substring aba marks the positions 1, 2, 3, 4, 5, 8, 9, 10; that is XXXXXewXXXq (X denotes

View Solution →

How Many Substrings?

Consider a string of n characters, s, of where each character is indexed from to . You are given queries in the form of two integer indices: and . For each query, count and print the number of different substrings of in the inclusive range between and . Note: Two substrings are different if their sequence of characters differs by at least one. For example, given the string aab, substrings a and a are the same but substrings aa and ab are different. Input Format The first li

View Solution →

Separate the Numbers

A numeric string, , is beautiful if it can be split into a sequence of two or more positive integers, , satisfying the following conditions: for any (i.e., each element in the sequence is more than the previous element). No contains a leading zero. For example, we can split into the sequence , but it is not beautiful because and have leading zeroes. The contents of the sequence cannot be rearranged. For example, we can split into the sequence , but it is not beautiful because it bre

View Solution →

Determining DNA Health

DNA is a nucleic acid present in the bodies of living things. Each piece of DNA contains a number of genes, some of which are beneficial and increase the DNA's total health. Each gene has a health value, and the total health of a DNA is the sum of the health values of all the beneficial genes that occur as a substring in the DNA. We represent genes and DNA as non-empty strings of lowercase English alphabetic letters, and the same gene may appear multiple times as a susbtring of a DNA. Given t

View Solution →