title-img


Subarray Division

Given a chocolate bar, two children, Lily and Ron, are determining how to share it. Each of the squares has an integer on it. Lily decides to share a contiguous segment of the bar selected such that: The length of the segment matches Ron's birth month, and, The sum of the integers on the squares is equal to his birth day. You must determine how many ways she can divide the chocolate. Consider the chocolate bar as an array of squares, s = [2, 2, 1, 3, 2]. She wants to find segments sum

View Solution →

Divisible Sum Pairs

Given an array of integers and a positive integer k, determine the number of (i, j) pairs where i<j and ar[i] + ar[j] is divisible by k. Example ar = [1, 2, 3, 4, 5, 6] k=5 Three pairs meet the criteria: [1, 4], [2, 3] and [4, 6]. Function Description Complete the divisibleSumPairs function in the editor below. divisibleSumPairs has the following parameter(s): int n: the length of array int ar[n]: an array of integers int k: the integer divisor Returns - int: the num

View Solution →

Migratory Birds

Given an array of bird sightings where every element represents a bird type id, determine the id of the most frequently sighted type. If more than 1 type has been spotted that maximum amount, return the smallest of their ids. Example arr = [1, 1, 2, 2, 3] There are two each of types 1 and 2, and one sighting of type 3. Pick the lower of the two types seen twice: type 1. Function Description Complete the migratoryBirds function in the editor below. migratoryBirds has the following

View Solution →

Day of the Programmer

Marie invented a Time Machine and wants to test it by time-traveling to visit Russia on the Day of the Programmer (the 256th day of the year) during a year in the inclusive range from 1700 to 2700. From 1700 to 1917, Russia's official calendar was the Julian calendar; since 1919 they used the Gregorian calendar system. The transition from the Julian to Gregorian calendar system occurred in 1918, when the next day after January 31st was February 14th. This means that in 1918, February 14th was

View Solution →

Bill Division

Two friends Anna and Brian, are deciding how to split the bill at a dinner. Each will only pay for the items they consume. Brian gets the check and calculates Anna's portion. You must determine if his calculation is correct. For example, assume the bill has the following prices: bill = [2, 4, 6]. Anna declines to eat item k= bill[2] which costs 6. If Brian calculates the bill correctly, Anna will pay (2+4)/2 = 3. If he includes the cost of bill[2], he will calculate (2 + 4 +6)/2 =6. In the se

View Solution →