You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a list of songs, the i-th song has a duration of time[i] seconds.
3
+
4
+
Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i < j with (time[i] + time[j]) % 60 == 0.
5
+
6
+
7
+
8
+
Example 1:
9
+
10
+
Input: [30,20,150,100,40]
11
+
Output: 3
12
+
Explanation: Three pairs have a total duration divisible by 60:
13
+
(time[0] = 30, time[2] = 150): total duration 180
14
+
(time[1] = 20, time[3] = 100): total duration 120
15
+
(time[1] = 20, time[4] = 40): total duration 60
16
+
Example 2:
17
+
18
+
Input: [60,60,60]
19
+
Output: 3
20
+
Explanation: All three pairs have a total duration of 120, which is divisible by 60.
21
+
22
+
Note:
23
+
24
+
1 <= time.length <= 60000
25
+
1 <= time[i] <= 500
26
+
'''
27
+
28
+
classSolution(object):
29
+
defnumPairsDivisibleBy60(self, time):
30
+
"""
31
+
:type time: List[int]
32
+
:rtype: int
33
+
"""
34
+
count_arr= [0]*60
35
+
result=0
36
+
fortintime:
37
+
remainder=t%60
38
+
complement= (60-remainder)%60
39
+
result+=count_arr[complement]
40
+
count_arr[remainder] +=1
41
+
returnresult
42
+
43
+
'''
44
+
Explanation:
45
+
Q1: why create array of size 60?
46
+
it is similar to the map which store the count. Why only 60 because 60 modulo of number cannot be more than 60
47
+
Q2: why we need complement?
48
+
to check the pair if it exisit with given value or not example: if remainder is 20 then we need to check if we have any number with remainder 40 or not.
A conveyor belt has packages that must be shipped from one port to another within D days.
3
+
4
+
The i-th package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship.
5
+
6
+
Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within D days.
7
+
8
+
9
+
10
+
Example 1:
11
+
12
+
Input: weights = [1,2,3,4,5,6,7,8,9,10], D = 5
13
+
Output: 15
14
+
Explanation:
15
+
A ship capacity of 15 is the minimum to ship all the packages in 5 days like this:
16
+
1st day: 1, 2, 3, 4, 5
17
+
2nd day: 6, 7
18
+
3rd day: 8
19
+
4th day: 9
20
+
5th day: 10
21
+
22
+
Note that the cargo must be shipped in the order given, so using a ship of capacity 14 and splitting the packages into parts like (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) is not allowed.
23
+
Example 2:
24
+
25
+
Input: weights = [3,2,2,4,1,4], D = 3
26
+
Output: 6
27
+
Explanation:
28
+
A ship capacity of 6 is the minimum to ship all the packages in 3 days like this:
In a list of songs, the i-th song has a duration of time[i] seconds.
2
+
Given an array A of integers, return true if and only if we can partition the array into three non-empty parts with equal sums.
3
3
4
-
Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i < j with (time[i] + time[j]) % 60 == 0.
4
+
Formally, we can partition the array if we can find indexes i+1 < j with (A[0] + A[1] + ... + A[i] == A[i+1] + A[i+2] + ... + A[j-1] == A[j] + A[j-1] + ... + A[A.length - 1])
5
5
6
6
7
7
8
8
Example 1:
9
9
10
-
Input: [30,20,150,100,40]
11
-
Output: 3
12
-
Explanation: Three pairs have a total duration divisible by 60:
it is similar to the map which store the count. Why only 60 because 60 modulo of number cannot be more than 60
47
-
Q2: why we need complement?
48
-
to check the pair if it exisit with given value or not example: if remainder is 20 then we need to check if we have any number with remainder 40 or not.
A conveyor belt has packages that must be shipped from one port to another within D days.
2
+
Given an array A of positive integers, A[i] represents the value of the i-th sightseeing spot, and two sightseeing spots i and j have distance j - i between them.
3
3
4
-
The i-th package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by weights). We may not load more weight than the maximum weight capacity of the ship.
4
+
The score of a pair (i < j) of sightseeing spots is (A[i] + A[j] + i - j) : the sum of the values of the sightseeing spots, minus the distance between them.
5
5
6
-
Return the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped within D days.
6
+
Return the maximum score of a pair of sightseeing spots.
7
7
8
8
9
9
10
10
Example 1:
11
11
12
-
Input: weights = [1,2,3,4,5,6,7,8,9,10], D = 5
13
-
Output: 15
14
-
Explanation:
15
-
A ship capacity of 15 is the minimum to ship all the packages in 5 days like this:
16
-
1st day: 1, 2, 3, 4, 5
17
-
2nd day: 6, 7
18
-
3rd day: 8
19
-
4th day: 9
20
-
5th day: 10
21
-
22
-
Note that the cargo must be shipped in the order given, so using a ship of capacity 14 and splitting the packages into parts like (2, 3, 4, 5), (1, 6, 7), (8), (9), (10) is not allowed.
23
-
Example 2:
24
-
25
-
Input: weights = [3,2,2,4,1,4], D = 3
26
-
Output: 6
27
-
Explanation:
28
-
A ship capacity of 6 is the minimum to ship all the packages in 3 days like this:
0 commit comments