title-img


Sherlock and Array

Watson gives Sherlock an array of integers. His challenge is to find an element of the array such that the sum of all elements to the left is equal to the sum of all elements to the right. Function Description Complete the balancedSums function in the editor below. balancedSums has the following parameter(s): int arr[n]: an array of integers Returns string: either YES or NO Input Format The first line contains , the number of test cases. The next pairs of lines each rep

View Solution →

Maximum Subarray Sum

We define the following: A subarray of array a of length n is a contiguous segment from a[ i ] through a[ j ] where 0 <= i <= j < n. The sum of an array is the sum of its elements. Given an n element array of integers, a, and an integer, m , determine the maximum value of the sum of any of its subarrays modulo m. For example, Assume a = [1, 2, 3 ]and m = 2 . The following table lists all subarrays and their moduli: sum %2 [1] 1 1 [2] 2 0 [3] 3 1 [1,2] 3 1 [2,3] 5 1 [1,2

View Solution →

Short Palindrome

Consider a string, , of lowercase English letters where each character, (, denotes the letter at index in . We define an palindromic tuple of to be a sequence of indices in satisfying the following criteria: , meaning the characters located at indices and are the same. , meaning the characters located at indices and are the same. , meaning that , , , and are ascending in value and are valid indices within string . Given , find and print the number of tuples satisfying the above

View Solution →

Maximizing Mission Points

Xander Cage has a list of cities he can visit on his new top-secret mission. He represents each city as a tuple of . The values of , , and are distinct across all cities. We define a mission as a sequence of cities, , that he visits. We define the total of such a mission to be the sum of the of all the cities in his mission list. Being eccentric, he abides by the following rules on any mission: He can choose the number of cities he will visit (if any). He can start the mission from

View Solution →

Count Luck

Ron and Hermione are deep in the Forbidden Forest collecting potion ingredients, and they've managed to lose their way. The path out of the forest is blocked, so they must make their way to a portkey that will transport them back to Hogwarts. Consider the forest as an grid. Each cell is either empty (represented by .) or blocked by a tree (represented by ). Ron and Hermione can move (together inside a single cell) LEFT, RIGHT, UP, and DOWN through empty cells, but they cannot travel through

View Solution →