title-img


Sherlock and Cost

In this challenge, you will be given an array B and must determine an array A. There is a special rule: For all i, A[i] <= B[i]. That is, A[i] can be any number you choose such that 1 <= A[i] <= B[i]. Your task is to select a series of A[i] given B[i] such that the sum of the absolute difference of consecutive pairs of A is maximized. This will be the array's cost, and will be represented by the variable S below. The equation can be written: S = (E^N )i=2 |A[i]-A[i-1]| For example, if t

View Solution →

Construct the Array

Your goal is to find the number of ways to construct an array such that consecutive positions contain different values. Specifically, we want to construct an array with n elements such that each element between 1 and k, inclusive. We also want the first and last elements of the array to be 1 and x. Given n, k and x, find the number of ways to construct such an array. Since the answer may be large, only find it modulo 10^9 + 7. For example, for n=4, k=3, x=2, there are 3 ways, as shown h

View Solution →

Kingdom Division

King Arthur has a large kingdom that can be represented as a tree, where nodes correspond to cities and edges correspond to the roads between cities. The kingdom has a total of n cities numbered from 1 to n. The King wants to divide his kingdom between his two children, Reggie and Betty, by giving each of them 0 or more cities; however, they don't get along so he must divide the kingdom in such a way that they will not invade each other's cities. The first sibling will invade the second sibli

View Solution →

Sam and substrings

Samantha and Sam are playing a numbers game. Given a number as a string, no leading zeros, determine the sum of all integer values of substrings of the string. Given an integer as a string, sum all of its substrings cast as integers. As the number may become large, return the value modulo 10^9 +7. Example n = '42' Here n is a string that has 3 integer substrings: 4, 2, and 42. Their sum is 48, and 48 modulo{10^9 +7)=48. Function Description Complete the substrings function in the e

View Solution →

Fibonacci Modified

Implement a modified Fibonacci sequence using the following definition: Given terms t[i] and t[i+1] where i ∈ (1,∞), term t[i+2] is computed as: t(i+2) = ti + t(i+2)^2 Given three integers, t1, t2, and n, compute and print the nth term of a modified Fibonacci sequence. Example t1 = 0 t2 =0 n =6 t3 = 0+1^2 = 1 t4 = 1+1^2 = 2 t5 = 1+2^2 = 5 t6 = 2+5^2 = 27 Return 27. Function Description Complete the fibonacciModified function in the editor below. It must return t

View Solution →