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 →Decibinary Numbers
Let's talk about binary numbers. We have an n-digit binary number, b , and we denote the digit at index i (zero-indexed from right to left) to be bi. We can find the decimal value of using the following formula: For example, if binary number b = 10010, we compute its decimal value like so: Meanwhile, in our well-known decimal number system where each digit ranges from 0 to 9, the value of some decimal number, d, can be expanded in the same way: Now that we've discussed both systems, l
View Solution →