Given an array which consists of non-negative integers and an integer m, you can split the array into m non-empty continuous subarrays. Write an algorithm to minimize the largest sum among these m subarrays.
If n is the length of array, assume the following constraints are satisfied:
12 1 ≤ n ≤ 10001 ≤ m ≤ min(50, n)
1234567891011 Input:nums = [7,2,5,10,8]m = 2Output:18Explanation:There are four ways to split nums into two subarrays.The best way is to split it into [7,2,5] and [10,8],where the largest sum among the two subarrays is only 18.
- Jun 23, 2017...more
- Jun 22, 2017...more
Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return the answers. If the answer does not exist, return -1.0.
Example:123456789101112131415161718Given a / b = 2.0, b / c = 3.0.queries are: a / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ? .return [6.0, 0.5, -1.0, 1.0, -1.0 ].The input is:vector<pair<string, string>> equations,vector<double>& values,vector<pair<string, string>> queries,where equations.size() == values.size(), and the values are positive. This represents the equations.Return vector<double>.According to the example above:equations = [ ["a", "b"], ["b", "c"] ],values = [2.0, 3.0],queries = [ ["a", "c"], ["b", "a"], ["a", "e"], ["a", "a"], ["x", "x"] ].
The input is always valid. You may assume that evaluating the queries will result in no division by zero and there is no contradiction.
- Jun 21, 2017...more
Follow up for “Unique Paths”:
Now consider if some obstacles are added to the grids. How many unique paths would there be?
An obstacle and empty space is marked as 1 and 0 respectively in the grid.
There is one obstacle in the middle of a 3x3 grid as illustrated below.12345[[0,0,0],[0,1,0],[0,0,0]]
The total number of unique paths is 2.
- m and n will be at most 100.
- Jun 20, 2017...more
The description of the problem you can see from HERE
- Jun 19, 2017...more
Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could be done in one interval. For each interval, CPU could finish one task or just be idle.
However, there is a non-negative cooling interval n that means between two same tasks, there must be at least n intervals that CPU are doing different tasks or just be idle.
You need to return the least number of intervals the CPU will take to finish all the given tasks.
Example 1:123Input: tasks = ['A','A','A','B','B','B'], n = 2Output: 8Explanation: A -> B -> idle -> A -> B -> idle -> A -> B.
- The number of tasks is in the range [1, 10000].
- The integer n is in the range [0, 100].