title-img


Two Strings

Given two strings, determine if they share a common substring. A substring may be as small as one character. Example s1 = 'and' s2 = 'art' These share the common substring a. s1 = 'be' s2 = 'cat' These do not share a substring. Function Description Complete the function twoStrings in the editor below. twoStrings has the following parameter(s): string s1: a string string s2: another string Returns string: either YES or NO Input Format The first line

View Solution →

Sherlock and the Valid String

Problem Statement : Sherlock considers a string to be valid if all characters of the string appear the same number of times. It is also valid if he can remove just 1 character at 1 index in the string, and the remaining characters will occur the same number of times. Given a string s, determine if it is valid. If so, return YES, otherwise return NO. Function Description Complete the isValid function in the editor below. isValid has the following parameter(s): string s: a string

View Solution →

Highest Value Palindrome

Palindromes are strings that read the same from the left or right, for example madam or 0110. You will be given a string representation of a number and a maximum number of changes you can make. Alter the string, one digit at a time, to create the string representation of the largest number possible given the limit to the number of changes. The length of the string may not be altered, so you must consider 0's left of all higher digits in your tests. For example 0110 is valid, 0011 is not.

View Solution →

Sherlock and Anagrams

Two strings are anagrams of each other if the letters of one string can be rearranged to form the other string. Given a string, find the number of pairs of substrings of the string that are anagrams of each other. For example s = mom , the list of all anagrammatic pairs is [m,m], [mo, om] at positions [ [1], [2], [0,1], [1,2] ] respectively . Function Description Complete the function sherlockAndAnagrams in the editor below. It must return an integer that represents the number of anagra

View Solution →

Common Child

A string is said to be a child of a another string if it can be formed by deleting 0 or more characters from the other string. Given two strings of equal length, what's the longest string that can be constructed such that it is a child of both? For example, ABCD and ABDC have two children with maximum length 3, ABC and ABD. They can be formed by eliminating either the D or C from both strings. Note that we will not consider ABCD as a common child because we can't rearrange characters and ABCD

View Solution →