title-img


Making Candies

Karl loves playing games on social networking sites. His current favorite is CandyMaker, where the goal is to make candies. Karl just started a level in which he must accumulate n candies starting with m machines and w workers. In a single pass, he can make m * w candies. After each pass, he can decide whether to spend some of his candies to buy more machines or hire more workers. Buying a machine or hiring a worker costs p units, and there is no limit to the number of machines he can own or

View Solution →

Max Array Sum

Given an array of integers, find the subset of non-adjacent elements with the maximum sum. Calculate the sum of that subset. It is possible that the maximum sum is 0, the case when all elements are negative. For example, given an array arr = [ -2, 1 , 3, -4, 5 ] we have the following possible subsets. These exclude the empty subset and single element subsets which are also valid. Subset Sum [-2, 3, 5] 6 [-2, 3] 1 [-2, -4] -6 [-2, 5] 3 [1, -4] -3 [1, 5]

View Solution →

Abbreviation

You can perform the following operations on the string, : 1. Capitalize zero or more of a's lowercase letters. 2. Delete all of the remaining lowercase letters in a. Given two strings, a and b, determine if it's possible to make a equal to b as described. If so, print YES on a new line. Otherwise, print NO. Function Description Complete the function abbrevation in the editor below. It must return either YES or NO. abbreviation has the following parameter(s): a: the string to m

View Solution →

Candies

Alice is a kindergarten teacher. She wants to give some candies to the children in her class. All the children sit in a line and each of them has a rating score according to his or her performance in the class. Alice wants to give at least 1 candy to each child. If two children sit next to each other, then the one with the higher rating must get more candies. Alice wants to minimize the total number of candies she must buy. Example arr = [ 4, 6, 4, 5 , 6 , 2 ] She gives the students

View Solution →

Sales by Match

There is a large pile of socks that must be paired by color. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are. Example n = 7 ar = [1, 2, 1, 2, 1, 3, 2] There is one pair of color 1 and one of color 2. There are three odd socks left, one of each color. The number of pairs is 2. Function Description Complete the sockMerchant function in the editor below. sockMerchant has the following parameter(s):

View Solution →