title-img


Alternating Characters

You are given a string containing characters A and B only. Your task is to change it into a string such that there are no matching adjacent characters. To do this, you are allowed to delete zero or more characters in the string. Your task is to find the minimum number of required deletions. Function Description Complete the alternatingCharacters function in the editor below. alternatingCharacters has the following parameter(s): string s: a string Returns int: the minimum num

View Solution →

Sherlock and the Valid String

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 Returns string: eit

View Solution →

Special String Again

A string is said to be a special string if either of two conditions is met: All of the characters are the same, e.g. aaa. All characters except the middle one are the same, e.g. aadaa. A special substring is any substring of a string which meets one of those criteria. Given a string, determine how many special substrings can be formed from it. Function Description Complete the substrCount function in the editor below. It should return an integer representing the number of special

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 →

Minimum Absolute Difference in an Array

The absolute difference is the positive difference between two values a and b, is written | a - b | or | b - a | and they are equal. If a = 3 and b = 20, | 3 - 2 | = | 2 - 3 | = 1 . Given an array of integers, find the minimum absolute difference between any two elements in the array. Function Description Complete the minimumAbsoluteDifference function in the editor below. It should return an integer that represents the minimum absolute difference between any pair of elements. mini

View Solution →