code
stringlengths
46
24k
language
stringclasses
6 values
AST_depth
int64
3
30
alphanumeric_fraction
float64
0.2
0.75
max_line_length
int64
13
399
avg_line_length
float64
5.01
139
num_lines
int64
7
299
task
stringlengths
151
14k
source
stringclasses
3 values
import functools class Solution: def minimum_Number(self, s): c = 0 arr = [] for i in s: if i != 0: arr.append(i) if i == '0': c += 1 if c == len(s): return s def fuc(a, b): if a + b > b + a: return 1 else: return -1 arr.sort() news = str(int(''.join(arr))) if c == 0: return news else: return news[0] + '0' * c + news[1:]
python
14
0.489529
38
13.692308
26
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): num = sorted(s) t = 0 for i in num: if i == '0': t += 1 else: break num = num[t:] if len(num) > 0: x = num[0] else: return '0' * t num = ['0'] * t + num[1:] num.insert(0, x) return ''.join(num)
python
11
0.487455
29
14.5
18
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): g = s.count('0') l = s.replace('0', '') if len(l) == 0: return s l = sorted(l) l.sort() h = [l[0]] for i in range(g): h.append('0') for i in range(1, len(l)): h.append(l[i]) return ''.join(h)
python
11
0.518797
29
16.733333
15
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): x = [i for i in s] x.sort() c = 0 for i in range(len(x)): if x[i] != '0': c = i break (x[0], x[c]) = (x[c], x[0]) return ''.join(x)
python
11
0.475248
29
15.833333
12
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): snum = sorted(list(s)) czero = snum.count('0') if czero == len(snum): return s snum[0] = snum[czero] snum[czero] = '0' return ''.join(snum)
python
11
0.608911
29
19.2
10
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): lst = [] for c in s: lst.append(c) lst.sort() n = len(lst) i = 0 while i < n and lst[i] == '0': i += 1 if i == n: return int(''.join(lst)) else: (lst[0], lst[i]) = (lst[i], lst[0]) return int(''.join(lst))
python
14
0.503521
38
16.75
16
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): s = sorted(s) ans = '' temp = '' flag = 1 for i in s: if i == '0': temp = temp + i flag = 0 else: ans = ans + i if flag == 0: ans = ans + temp flag = 1 if len(ans) == 0: return temp return ans if __name__ == '__main__': T = int(input()) for i in range(T): s = input() ob = Solution() ans = ob.minimum_Number(s) print(ans)
python
15
0.5
29
15.461538
26
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): l = list(s) l.sort() for i in range(len(l)): if int(l[i]) > 0: (l[0], l[i]) = (l[i], l[0]) break n = '' for i in l: n += i return n if __name__ == '__main__': T = int(input()) for i in range(T): s = input() ob = Solution() ans = ob.minimum_Number(s) print(ans)
python
13
0.5
31
16.2
20
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): x = list(sorted(s)) k = '' for i in x: if i != '0': k += i break if len(k) == 0: return s x.remove(k[0]) for i in x: k += i return k if __name__ == '__main__': T = int(input()) for i in range(T): s = input() ob = Solution() ans = ob.minimum_Number(s) print(ans)
python
11
0.508571
29
14.909091
22
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): arr = list(s) arr.sort() for i in range(len(arr)): if arr[i] != '0': temp = arr[i] arr.pop(i) break if len(arr) == len(s): return s else: return temp + ''.join(arr)
python
13
0.547325
29
16.357143
14
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): res = [int(x) for x in str(s)] mo = '' res.sort() if res[len(res) - 2] == 0: res.sort(reverse=True) for s in res: mo = mo + str(s) return int(mo) if res[0] == 0: for i in range(len(res) - 1): if res[i] > 0: res[0] = res[i] res[i] = 0 break for s in res: mo = mo + str(s) return int(mo)
python
14
0.511688
32
18.25
20
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): s = list(s) s.sort() ind = 0 leng = len(s) while ind < leng and s[ind] == '0': ind += 1 if ind == leng: return int(''.join(s)) p = s.pop(ind) s.insert(0, p) return int(''.join(s))
python
13
0.537849
37
16.928571
14
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): dic = {} for el in range(10): dic[str(el)] = 0 if s[0] != '-': for el in s: dic[el] += 1 newS = '' for el in range(1, 10): newS += str(el) * dic[str(el)] if dic['0'] != 0 and len(newS) > 0: newS = newS[0] + '0' * dic['0'] + newS[1:] elif dic['0'] != 0 and len(newS) == 0: newS += '0' * dic['0'] return newS else: for el in s[1:]: dic[el] += 1 newS = '' for el in range(9, -1, -1): newS += str(el) * dic[str(el)] newS = '-' + newS return newS
python
16
0.472172
46
21.28
25
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): s = sorted(s) if s[-1] == '0': return ''.join(s) i = 0 while s[i] == '0': i += 1 (s[i], s[0]) = (s[0], s[i]) return ''.join(s)
python
11
0.463542
29
16.454545
11
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): n = len(s) s = list(s) s = sorted(s) i = 0 while i < n - 1 and s[i] == '0': i += 1 if i == 0: return ''.join(s) else: (s[0], s[i]) = (s[i], s[0]) return ''.join(s)
python
12
0.461864
34
15.857143
14
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): lst = list(s) num = sorted(lst) num = ''.join(num) num = list(num) for i in range(len(num)): if num[i] == '0': continue (num[i], num[0]) = (num[0], num[i]) return ''.join(num) return ''.join(num)
python
11
0.552239
38
19.615385
13
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, n): arr = sorted([int(i) for i in list(str(n))]) zcount = arr.count(0) if zcount == 0: return int(''.join(arr)) elif zcount == len(arr): return 0 else: s = str(arr[zcount]) for _ in range(zcount): s += '0' for i in arr[zcount + 1:]: s += str(i) return int(s)
python
15
0.56213
46
20.125
16
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
import heapq class Solution: def minimum_Number(self, s): s = list(s) s.sort() s.append('-1') i = 0 while s[i] == '0': i += 1 if i == len(s) - 1: return 0 s.pop() (s[0], s[i]) = (s[i], s[0]) return ''.join(s)
python
10
0.483051
29
13.75
16
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minimum_Number(self, s): n = len(s) ls = list(s) ls.sort() i = 0 while i < n and ls[i] == '0': i += 1 if i < n: (ls[0], ls[i]) = (ls[i], ls[0]) return ''.join(ls)
python
11
0.478049
34
16.083333
12
Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearranging the digits. Example 2: Input: s = "55010" Output: 10055 Explanation: 10055 is the smallest number by rearranging the digts. Your Task: You don't need to read or print anything. Your task is to complete the function minimum_number() which takes the number as input parameter and returns the smallest number than can be formed without leading zeros by rearranging the digits of the number. Expected Time Complexity: O(N * log(N)) where N is the number of digits of the given number Expected Space Complexity: O(1) Constraints: 1 <= N <= 10^{5}
taco
class Solution: def minTime(self, arr, n, k): def numofPainter(maxLen): painters = 1 total = 0 for board in arr: total += board if total > maxLen: total = board painters += 1 return painters (low, high) = (max(arr), sum(arr)) while low < high: p = low + (high - low) // 2 curr_painters = numofPainter(p) if curr_painters <= k: high = p else: low = p + 1 return low
python
13
0.570423
36
18.363636
22
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board. The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}. Example 1: Input: n = 5 k = 3 arr[] = {5,10,30,20,15} Output: 35 Explanation: The most optimal way will be: Painter 1 allocation : {5,10} Painter 2 allocation : {30} Painter 3 allocation : {20,15} Job will be done when all painters finish i.e. at time = max(5+10, 30, 20+15) = 35 Example 2: Input: n = 4 k = 2 arr[] = {10,20,30,40} Output: 60 Explanation: The most optimal way to paint: Painter 1 allocation : {10,20,30} Painter 2 allocation : {40} Job will be complete at time = 60 Your task: Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions. Expected Time Complexity: O(n log m) , m = sum of all boards' length Expected Auxiliary Space: O(1) Constraints: 1 ≀ n ≀ 10^{5} 1 ≀ k ≀ 10^{5} 1 ≀ arr[i] ≀ 10^{5}
taco
class Solution: def minTime(self, arr, n, k): def numOfPainter(maxLen): painters = 1 total = 0 for board in arr: total += board if total > maxLen: total = board painters += 1 return painters (low, high) = (max(arr), sum(arr)) while low < high: pivot = low + (high - low) // 2 currPainters = numOfPainter(pivot) if currPainters <= k: high = pivot else: low = pivot + 1 return low
python
13
0.588636
37
19
22
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board. The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}. Example 1: Input: n = 5 k = 3 arr[] = {5,10,30,20,15} Output: 35 Explanation: The most optimal way will be: Painter 1 allocation : {5,10} Painter 2 allocation : {30} Painter 3 allocation : {20,15} Job will be done when all painters finish i.e. at time = max(5+10, 30, 20+15) = 35 Example 2: Input: n = 4 k = 2 arr[] = {10,20,30,40} Output: 60 Explanation: The most optimal way to paint: Painter 1 allocation : {10,20,30} Painter 2 allocation : {40} Job will be complete at time = 60 Your task: Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions. Expected Time Complexity: O(n log m) , m = sum of all boards' length Expected Auxiliary Space: O(1) Constraints: 1 ≀ n ≀ 10^{5} 1 ≀ k ≀ 10^{5} 1 ≀ arr[i] ≀ 10^{5}
taco
class Solution: def numberOfPainters(self, arr, n, maxLen): total = 0 numPainters = 1 for i in arr: total += i if total > maxLen: total = i numPainters += 1 return numPainters def minTime(self, arr, n, k): lo = max(arr) hi = sum(arr) while lo < hi: mid = lo + (hi - lo) // 2 requiredPainters = self.numberOfPainters(arr, n, mid) if requiredPainters <= k: hi = mid else: lo = mid + 1 return lo
python
13
0.595078
56
18.434783
23
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board. The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}. Example 1: Input: n = 5 k = 3 arr[] = {5,10,30,20,15} Output: 35 Explanation: The most optimal way will be: Painter 1 allocation : {5,10} Painter 2 allocation : {30} Painter 3 allocation : {20,15} Job will be done when all painters finish i.e. at time = max(5+10, 30, 20+15) = 35 Example 2: Input: n = 4 k = 2 arr[] = {10,20,30,40} Output: 60 Explanation: The most optimal way to paint: Painter 1 allocation : {10,20,30} Painter 2 allocation : {40} Job will be complete at time = 60 Your task: Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions. Expected Time Complexity: O(n log m) , m = sum of all boards' length Expected Auxiliary Space: O(1) Constraints: 1 ≀ n ≀ 10^{5} 1 ≀ k ≀ 10^{5} 1 ≀ arr[i] ≀ 10^{5}
taco
class Solution: def ifpossible(self, arr, n, k, mid): load = 0 painter = 1 for board in arr: load += board if load > mid: painter += 1 load = board return painter <= k def recursion(self, arr, n, k, start, end, ans): if start > end: return ans mid = (start + end) // 2 output = self.ifpossible(arr, n, k, mid) if output: ans = mid end = mid - 1 return self.recursion(arr, n, k, start, end, ans) else: start = mid + 1 return self.recursion(arr, n, k, start, end, ans) def minTime(self, arr, n, k): (start, end) = (max(arr), sum(arr)) ans = -1 return self.recursion(arr, n, k, start, end, ans)
python
11
0.590214
52
21.551724
29
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board. The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}. Example 1: Input: n = 5 k = 3 arr[] = {5,10,30,20,15} Output: 35 Explanation: The most optimal way will be: Painter 1 allocation : {5,10} Painter 2 allocation : {30} Painter 3 allocation : {20,15} Job will be done when all painters finish i.e. at time = max(5+10, 30, 20+15) = 35 Example 2: Input: n = 4 k = 2 arr[] = {10,20,30,40} Output: 60 Explanation: The most optimal way to paint: Painter 1 allocation : {10,20,30} Painter 2 allocation : {40} Job will be complete at time = 60 Your task: Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions. Expected Time Complexity: O(n log m) , m = sum of all boards' length Expected Auxiliary Space: O(1) Constraints: 1 ≀ n ≀ 10^{5} 1 ≀ k ≀ 10^{5} 1 ≀ arr[i] ≀ 10^{5}
taco
class Solution: def isPossible(arr, n, k, mid): time_sum = 0 painter_count = 1 for i in range(n): if time_sum + arr[i] <= mid: time_sum += arr[i] else: painter_count += 1 if painter_count > k or arr[i] > mid: return False time_sum = arr[i] return True def minTime(self, arr, n, k): low = 0 high = sum(arr) mid = int(low + (high - low) / 2) ans = -1 while low <= high: if Solution.isPossible(arr, n, k, mid): ans = mid high = mid - 1 else: low = mid + 1 mid = int(low + (high - low) / 2) return ans
python
15
0.547368
42
19.357143
28
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board. The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}. Example 1: Input: n = 5 k = 3 arr[] = {5,10,30,20,15} Output: 35 Explanation: The most optimal way will be: Painter 1 allocation : {5,10} Painter 2 allocation : {30} Painter 3 allocation : {20,15} Job will be done when all painters finish i.e. at time = max(5+10, 30, 20+15) = 35 Example 2: Input: n = 4 k = 2 arr[] = {10,20,30,40} Output: 60 Explanation: The most optimal way to paint: Painter 1 allocation : {10,20,30} Painter 2 allocation : {40} Job will be complete at time = 60 Your task: Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions. Expected Time Complexity: O(n log m) , m = sum of all boards' length Expected Auxiliary Space: O(1) Constraints: 1 ≀ n ≀ 10^{5} 1 ≀ k ≀ 10^{5} 1 ≀ arr[i] ≀ 10^{5}
taco
class Solution: def minTime(self, arr, n, k): s = 0 sumi = 0 ans = -1 for i in arr: sumi = sumi + i e = sumi mid = (s + e) // 2 while s <= e: if n == 1: return arr[0] if self.ispossible(arr, n, k, mid): ans = mid e = mid - 1 else: s = mid + 1 mid = (s + e) // 2 return ans def ispossible(self, arr, n, k, mid): sc = 1 ps = 0 for i in range(len(arr)): if ps + arr[i] <= mid: ps += arr[i] else: sc += 1 if sc > k or arr[i] > mid: return False ps = arr[i] return True
python
14
0.480944
38
15.69697
33
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board. The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}. Example 1: Input: n = 5 k = 3 arr[] = {5,10,30,20,15} Output: 35 Explanation: The most optimal way will be: Painter 1 allocation : {5,10} Painter 2 allocation : {30} Painter 3 allocation : {20,15} Job will be done when all painters finish i.e. at time = max(5+10, 30, 20+15) = 35 Example 2: Input: n = 4 k = 2 arr[] = {10,20,30,40} Output: 60 Explanation: The most optimal way to paint: Painter 1 allocation : {10,20,30} Painter 2 allocation : {40} Job will be complete at time = 60 Your task: Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions. Expected Time Complexity: O(n log m) , m = sum of all boards' length Expected Auxiliary Space: O(1) Constraints: 1 ≀ n ≀ 10^{5} 1 ≀ k ≀ 10^{5} 1 ≀ arr[i] ≀ 10^{5}
taco
def isValid(mid, arr, n, k): sum_ = 0 count = 1 for i in arr: sum_ += i if sum_ > mid: count += 1 sum_ = i if count > k: return False return True class Solution: def minTime(self, arr, n, k): (l, r) = (max(arr), sum(arr)) while l <= r: mid = l + (r - l) // 2 if isValid(mid, arr, n, k): r = mid - 1 else: l = mid + 1 return l
python
13
0.49866
31
15.217391
23
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board. The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}. Example 1: Input: n = 5 k = 3 arr[] = {5,10,30,20,15} Output: 35 Explanation: The most optimal way will be: Painter 1 allocation : {5,10} Painter 2 allocation : {30} Painter 3 allocation : {20,15} Job will be done when all painters finish i.e. at time = max(5+10, 30, 20+15) = 35 Example 2: Input: n = 4 k = 2 arr[] = {10,20,30,40} Output: 60 Explanation: The most optimal way to paint: Painter 1 allocation : {10,20,30} Painter 2 allocation : {40} Job will be complete at time = 60 Your task: Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions. Expected Time Complexity: O(n log m) , m = sum of all boards' length Expected Auxiliary Space: O(1) Constraints: 1 ≀ n ≀ 10^{5} 1 ≀ k ≀ 10^{5} 1 ≀ arr[i] ≀ 10^{5}
taco
class Solution: def minTime(self, arr, n, k): l = 0 r = 0 for i in range(len(arr)): r = r + arr[i] mid = l + (r - l) // 2 ans = -1 def ispossible(mid, arr, k): pc = 1 cs = 0 for i in range(len(arr)): if cs + arr[i] <= mid: cs = cs + arr[i] else: pc = pc + 1 if pc > k or arr[i] > mid: return False cs = arr[i] return True while l <= r: mid = l + (r - l) // 2 if ispossible(mid, arr, k): ans = mid r = mid - 1 else: l = mid + 1 return ans
python
16
0.462998
31
16.566667
30
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board. The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}. Example 1: Input: n = 5 k = 3 arr[] = {5,10,30,20,15} Output: 35 Explanation: The most optimal way will be: Painter 1 allocation : {5,10} Painter 2 allocation : {30} Painter 3 allocation : {20,15} Job will be done when all painters finish i.e. at time = max(5+10, 30, 20+15) = 35 Example 2: Input: n = 4 k = 2 arr[] = {10,20,30,40} Output: 60 Explanation: The most optimal way to paint: Painter 1 allocation : {10,20,30} Painter 2 allocation : {40} Job will be complete at time = 60 Your task: Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions. Expected Time Complexity: O(n log m) , m = sum of all boards' length Expected Auxiliary Space: O(1) Constraints: 1 ≀ n ≀ 10^{5} 1 ≀ k ≀ 10^{5} 1 ≀ arr[i] ≀ 10^{5}
taco
class Solution: def minTime(self, arr, n, k): sum = 0 for i in arr: sum += i low = 0 high = sum mid = (low + high) // 2 ans = -1 while low <= high: if possible(arr, n, k, mid): ans = mid high = mid - 1 else: low = mid + 1 mid = (low + high) // 2 return ans def possible(arr, n, k, mid): c = 1 sum = 0 for i in range(n): if sum + arr[i] <= mid: sum = sum + arr[i] else: sum = arr[i] c = c + 1 if c > k or arr[i] > mid: return False return True
python
13
0.503922
31
15.451613
31
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board. The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}. Example 1: Input: n = 5 k = 3 arr[] = {5,10,30,20,15} Output: 35 Explanation: The most optimal way will be: Painter 1 allocation : {5,10} Painter 2 allocation : {30} Painter 3 allocation : {20,15} Job will be done when all painters finish i.e. at time = max(5+10, 30, 20+15) = 35 Example 2: Input: n = 4 k = 2 arr[] = {10,20,30,40} Output: 60 Explanation: The most optimal way to paint: Painter 1 allocation : {10,20,30} Painter 2 allocation : {40} Job will be complete at time = 60 Your task: Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions. Expected Time Complexity: O(n log m) , m = sum of all boards' length Expected Auxiliary Space: O(1) Constraints: 1 ≀ n ≀ 10^{5} 1 ≀ k ≀ 10^{5} 1 ≀ arr[i] ≀ 10^{5}
taco
def is_anagram(test, original): (test_dict, original_dict) = ({}, {}) for i in test.lower(): test_dict[i] = test_dict.get(i, 0) + 1 for i in original.lower(): original_dict[i] = original_dict.get(i, 0) + 1 return test_dict == original_dict
python
10
0.637097
48
34.428571
7
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): if len(test) != len(original): return False count = [0] * 26 for i in range(len(test)): count[(ord(test[i]) & 31) - 1] += 1 count[(ord(original[i]) & 31) - 1] -= 1 return not any(count)
python
14
0.596491
41
27.5
8
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): a = sorted(test.lower()) b = sorted(original.lower()) c = ''.join(a) d = ''.join(b) if c == d: return True else: return False
python
9
0.60119
31
17.666667
9
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): go = len(test) == len(original) arr = [] if go: for i in test: arr.append(i.lower() in original.lower()) return False not in arr else: return False
python
13
0.647668
44
20.444444
9
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): if len(test) != len(original): return False for l in test.lower(): if l not in original.lower(): return False return True
python
9
0.682927
31
22.428571
7
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
aprime = {'a': 2, 'c': 5, 'b': 3, 'e': 11, 'd': 7, 'g': 17, 'f': 13, 'i': 23, 'h': 19, 'k': 31, 'j': 29, 'm': 41, 'l': 37, 'o': 47, 'n': 43, 'q': 59, 'p': 53, 's': 67, 'r': 61, 'u': 73, 't': 71, 'w': 83, 'v': 79, 'y': 97, 'x': 89, 'z': 101} def aprime_sum(str): strChList = list(str.lower()) return sum([aprime[x] for x in strChList]) def is_anagram(test, original): if aprime_sum(test) == aprime_sum(original): return True else: return False
python
9
0.505519
240
40.181818
11
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): a = list(test.lower()) s = list(original.lower()) if len(a) != len(s): return False else: for i in a: cond = False k = 0 while k != len(s) and cond == False: if i == s[k]: a.remove(i) s.remove(i) cond = True k += 1 if cond == False: return False if len(a) != len(s): return False else: return True
python
15
0.540052
39
17.428571
21
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): flag = 0 if len(test) != len(original): return False else: for i in test.lower(): if i not in original.lower(): flag = 1 else: continue if flag == 1: return False else: return True
python
12
0.610656
32
16.428571
14
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): def to_dict(word): dictionary = {} for w in word.lower(): if w not in dictionary: dictionary[w] = 0 else: dictionary[w] += 1 return dictionary return to_dict(test) == to_dict(original)
python
13
0.641667
42
20.818182
11
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(s, l): n = len(s) if len(l) != n: return False s = s.lower() l = l.lower() h = [0 for x in range(26)] for i in range(n): h[ord(s[i]) - 97] += 1 h[ord(l[i]) - 97] -= 1 return h.count(0) == 26
python
12
0.506849
27
18.909091
11
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test = test.lower() original = original.lower() testcount = 0 for i in test: if i in original: testcount += 1 originalcount = 0 for i in original: if i in test: originalcount += 1 if testcount == originalcount and testcount == len(test) and (originalcount == len(original)): return True else: return False
python
9
0.686111
95
23
15
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): if len(test) == len(original): test = test.lower() original = original.lower() count = 0 for char in test: if char in original: count += 1 if count == len(test): return True else: return False else: return False
python
11
0.6337
31
18.5
14
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test_list = [] original_list = [] for i in test.lower(): test_list.append(i) for i in original.lower(): original_list.append(i) test_list.sort() original_list.sort() print(test_list) print(original_list) if test_list == original_list: return True else: return False
python
8
0.686709
31
20.066667
15
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): if len(test) != len(original): return False letters = {} for i in test.lower(): if i in letters: letters[i] += 1 else: letters[i] = 1 for i in original.lower(): if i not in letters: return False if original.lower().count(i) != letters[i]: return False return True
python
11
0.637771
45
20.533333
15
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): x = list(test.lower()) y = list(original.lower()) x = sorted(x) y = sorted(y) if x == y: return True else: return False
python
9
0.623457
31
17
9
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): if len(test) != len(original): return False a = sorted(test.lower()) b = sorted(original.lower()) if a == b: return True else: return False
python
9
0.655738
31
19.333333
9
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): letters = [c for c in test.lower()] for char in original.lower(): if char in letters: del letters[letters.index(char)] else: return False return not bool(len(letters))
python
11
0.694836
36
25.625
8
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test_set = sorted(test.lower()) original_set = sorted(original.lower()) if test_set == original_set: return True else: return False
python
9
0.703488
40
23.571429
7
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): t = sorted(test.lower()) o = sorted(original.lower()) if t == o: return True else: return False
python
9
0.654412
31
18.428571
7
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): new_test = test.lower() new_original = original.lower() sortedTest = sorted(new_test) sortedOriginal = sorted(new_original) for letters in new_test: if letters in new_original and len(new_test) == len(new_original) and (sortedOriginal == sortedTest): return True else: return False
python
11
0.723404
103
31.9
10
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test_word_freq = {} original_word_freq = {} test = test.lower() original = original.lower() if len(test) == len(original): for (idx, letter) in enumerate(test): if letter not in test_word_freq: test_word_freq[letter] = 1 else: test_word_freq[letter] += 1 for (idx, lett) in enumerate(original): if lett not in original_word_freq: original_word_freq[lett] = 1 else: original_word_freq[lett] += 1 print(original_word_freq) print(test_word_freq) for (k, v) in list(test_word_freq.items()): if k not in original_word_freq: return False if v != original_word_freq[k]: return False return True else: return False
python
13
0.654779
45
25.961538
26
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): list_test = [] list_original = [] for i in test.lower(): list_test += i for i in original.lower(): list_original += i if len(list_test) == len(list_original): list_test.sort() list_original.sort() if list_test == list_original: return True else: return False else: return False
python
9
0.64881
41
20
16
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): t = list(test.lower()) to = ''.join(sorted(t)) o = list(original.lower()) oo = ''.join(sorted(o)) if to == oo: return True else: return False
python
9
0.61413
31
19.444444
9
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): letterCount = dict.fromkeys('abcdefghijklmnopqrstuvwxyz', 0) for c in test.lower(): letterCount[c] += 1 for c in original.lower(): letterCount[c] -= 1 for value in list(letterCount.values()): if value != 0: return False return True
python
8
0.697842
61
26.8
10
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(a_str, b_str): if len(a_str) == len(b_str): a_list = list(a_str.lower()) b_list = list(b_str.lower()) for char in a_list: if char in b_list: b_list.remove(char) if not b_list: return True else: return False else: return False
python
12
0.61194
30
19.615385
13
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): if len(test) != len(original): return False else: test = test.lower() original = original.lower() counter_original = [0] * 26 counter_test = [0] * 26 for i in test: counter_test[ord(i) - 97] += 1 for i in original: counter_original[ord(i) - 97] += 1 return counter_test == counter_original
python
14
0.64058
40
25.538462
13
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test = test.lower() original = original.lower() newList = [ord(c) for c in test] newList.sort() newList2 = [ord(b) for b in original] newList2.sort() if newList == newList2: return True else: return False
python
8
0.682731
38
21.636364
11
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): counterTest = [0] * 255 counterOri = [0] * 255 for i in range(len(test)): counterTest[ord(test[i].lower())] += 1 for i in range(len(original)): counterOri[ord(original[i].lower())] += 1 if counterOri == counterTest: return True else: return False
python
13
0.662116
43
25.636364
11
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test = test.upper() original = original.upper() if sorted(test) == sorted(original): return True else: return False
python
7
0.698718
37
21.285714
7
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): if len(test) == len(original): test = test.lower() original = original.lower() for i in test: if original.find(i) == -1: return False else: test.replace(i, '') original.replace(i, '') else: return False return True
python
14
0.623188
31
20.230769
13
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): counter1 = [0] * 255 counter2 = [0] * 255 for i in range(len(test)): counter1[ord(test[i].lower())] += 1 for i in range(len(original)): counter2[ord(original[i].lower())] += 1 return counter1 == counter2
python
13
0.644898
41
29.625
8
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test = test.lower() original = original.lower() for x in range(len(test)): if test.count(test[x]) != original.count(test[x]): return False for x in range(len(original)): if test.count(original[x]) != original.count(original[x]): return False return True
python
10
0.684385
60
29.1
10
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test = test.lower() original = original.lower() nT = len(test) nO = len(original) if nO == nT: counterT = [0] * (255 + 1) counterO = [0] * (255 + 1) for x in range(nT): counterT[ord(test[x])] += 1 counterO[ord(original[x])] += 1 if counterT == counterO: return True else: return False else: return False
python
13
0.603825
34
20.529412
17
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): n = len(original) if n != len(test): return False counterTest = [0] * 255 counterOrig = [0] * 255 for i in range(n): counterTest[ord(test[i].lower())] += 1 counterOrig[ord(original[i].lower())] += 1 return True if ''.join(map(str, counterTest)) == ''.join(map(str, counterOrig)) else False
python
13
0.646707
91
32.4
10
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(word_o, test_o): is_anagram = True word = word_o.lower() test = test_o.lower() if len(word) != len(test): is_anagram = False alist = list(test.lower()) pos1 = 0 while pos1 < len(word) and is_anagram: pos2 = 0 found = False while pos2 < len(alist) and (not found): if word[pos1] == alist[pos2]: found = True else: pos2 = pos2 + 1 if found: alist[pos2] = None else: is_anagram = False pos1 = pos1 + 1 return is_anagram
python
13
0.611814
42
20.545455
22
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): l1 = list(test.lower()) l2 = list(original.lower()) if len(l1) == len(l2): for i in l1: if i in l2: l2.remove(i) else: return False else: return False return True
python
12
0.614679
31
17.166667
12
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): for i in test.lower(): if i in original.lower() and len(test) == len(original): continue else: return False return True
python
10
0.676829
58
22.428571
7
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test_list = [letter1 for letter1 in test.lower()] orig_list = [letter2 for letter2 in original.lower()] if sorted(test_list) == sorted(orig_list): return True else: return False
python
9
0.711009
54
30.142857
7
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): t = sorted(test.lower()) o = sorted(original.lower()) if t == o: print('true') return True else: print('false') return False
python
10
0.639053
31
17.777778
9
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test = test.lower() original = original.lower() if len(test) != len(original): return False for x in test: if test.count(x) == original.count(x): continue else: return False return True
python
9
0.67234
40
20.363636
11
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test = test.lower() original = original.lower() new_test = list(test) new_original = list(original) new_test.sort() new_original.sort() if new_test == new_original: return True return False pass
python
7
0.701681
31
20.636364
11
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): originalLower = [val for val in original.lower()] arr = test.lower() if len(arr) != len(originalLower): return False for element in arr: if element not in originalLower: return False else: originalLower.remove(element) return True
python
11
0.717857
50
24.454545
11
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): n1 = len(test) n2 = len(original) if n1 != n2: return False str1 = sorted(test.lower()) str2 = sorted(original.lower()) for i in range(0, n1): if str1[i] != str2[i]: return False return True
python
9
0.64135
32
20.545455
11
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test_l = list(test.lower()) original_l = list(original.lower()) test_l.sort() original_l.sort() if test_l == original_l: return True else: return False
python
9
0.675258
36
20.555556
9
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test = list(test.lower()) original = list(original.lower()) if len(test) != len(original): return False for word in test: for word2 in original: if word == word2: original.remove(word2) break if len(original) == 0: return True else: return False
python
12
0.666667
34
20.642857
14
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): a = sorted(list(test.lower())) b = sorted(list(original.lower())) if a == b: print(f'The word {test} is an anagram of {original}') return True else: print(f'Characters do not match for test case {test}, {original}') return False
python
11
0.673993
68
29.333333
9
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): def to_list(string): listed = [] for i in range(len(string)): listed.append(string[i]) return listed return str(sorted(to_list(test.lower()))) == str(sorted(to_list(original.lower())))
python
13
0.672489
84
27.625
8
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test = list(test.lower()) test.sort() original = list(original.lower()) original.sort() if original != test or len(test) != len(original): return False else: return True
python
9
0.683962
51
22.555556
9
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): if len(test) != len(original): return False test = sorted(test.lower()) original = sorted(original.lower()) for i in range(len(test)): if test[i] != original[i]: return False return True
python
9
0.675325
36
24.666667
9
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): if len(original) != len(test): return False test = test.lower() original = original.lower() for letter in original: if original.count(letter) != test.count(letter): return False return True
python
9
0.705128
50
25
9
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test_list = sorted(list(test.lower())) original_list = sorted(list(original.lower())) if test_list == original_list: return True if test_list != original_list: return False
python
11
0.70892
47
29.428571
7
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test = test.lower() original = original.lower() t = list(test) o = list(original) t.sort() o.sort() return t == o
python
7
0.640523
31
18.125
8
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): t = test.lower() o = [*original.lower()] if len(t) != len(o): return False for c in t: if c in o: o.remove(c) else: return False return True
python
10
0.605263
31
16.272727
11
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): if len(test) > len(original) or len(test) < len(original): return False res = '' counter = 0 sortedTest = sorted(test.lower()) sortedOriginal = sorted(original.lower()) for i in range(0, len(sortedTest)): if sortedTest[i] != sortedOriginal[i]: res = False break else: res = True return res
python
10
0.668605
59
23.571429
14
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): sort1 = sorted(test.lower()) sort2 = sorted(original.lower()) if ''.join(sort2) == ''.join(sort1): return True else: return False
python
9
0.664706
37
23.285714
7
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): theTest = test.lower() theOriginal = original.lower() if len(theTest) != len(theOriginal): return False else: index = 0 lengthCheck = 0 array = [None] * len(theTest) for i in theOriginal: array[index] = i index += 1 for j in theTest: testLength = len(theTest) if j in array: lengthCheck += 1 else: return False if lengthCheck == testLength: return True
python
12
0.65035
37
20.45
20
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(tst, org): tst = tst.lower() org = org.lower() if len(tst) != len(org): return False for i in org: if tst.count(i) != org.count(i): return False return True
python
9
0.625
34
19.444444
9
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): if len(test) != len(original): return False elif sorted(test.casefold()) == sorted(original.casefold()): return True else: return False
python
10
0.700565
61
24.285714
7
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): org1 = [x.lower() for x in original] org2 = [y.lower() for y in test] org1.sort() org2.sort() if org1 == org2: return True return False
python
8
0.653409
37
21
8
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): original_list = list(original.lower()) test_list = list(test.lower()) original_list.sort() test_list.sort() a = ''.join(test_list) b = ''.join(original_list) return a == b
python
9
0.663507
39
25.375
8
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
def is_anagram(test, original): test = test.lower().replace(' ', '') original = original.lower().replace(' ', '') if len(test) != len(original): return False for letter in test: if letter not in original: return False for letter in original: if letter not in test: return False return True
python
9
0.672078
45
24.666667
12
An **anagram** is the result of rearranging the letters of a word to produce a new word. **Note:** anagrams are case insensitive Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise. ## Examples * `"foefet"` is an anagram of `"toffee"` * `"Buckethead"` is an anagram of `"DeathCubeK"`
taco
import sys n = int(input()) a = [int(x) for x in input().split(' ')] maxm = 0 idx = 0 ans = 0 b = [0] * n for i in range(n): if a[i] >= maxm: maxm = a[i] idx = i for i in range(idx, n): b[i] = maxm + 1 i = idx - 1 while i >= 0: b[i] = max(a[i] + 1, b[i + 1] - 1) i -= 1 for i in range(1, n): if b[i] < b[i - 1]: b[i] = b[i - 1] ans += b[i] - 1 - a[i] print(ans)
python
10
0.465241
40
16
22
Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi. Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day. Input The first line contains a single positive integer n (1 ≀ n ≀ 105) β€” the number of days. The second line contains n space-separated integers m1, m2, ..., mn (0 ≀ mi < i) β€” the number of marks strictly above the water on each day. Output Output one single integer β€” the minimum possible sum of the number of marks strictly below the water level among all days. Examples Input 6 0 1 0 3 0 2 Output 6 Input 5 0 1 2 1 2 Output 1 Input 5 0 1 1 2 2 Output 0 Note In the first example, the following figure shows an optimal case. <image> Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6. In the second example, the following figure shows an optimal case. <image>
taco
n = int(input()) a = list(map(int, input().split())) min_toptal = a.copy() for i in range(1, n): min_toptal[i] = max(min_toptal[i - 1], a[i] + 1) min_toptal[0] = 1 for i in range(n - 1, 0, -1): min_toptal[i - 1] = max(min_toptal[i] - 1, min_toptal[i - 1]) min_under = [] underwater = sum((max(0, min_toptal[i] - a[i] - 1) for i in range(n))) print(underwater)
python
11
0.582873
70
31.909091
11
Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi. Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day. Input The first line contains a single positive integer n (1 ≀ n ≀ 105) β€” the number of days. The second line contains n space-separated integers m1, m2, ..., mn (0 ≀ mi < i) β€” the number of marks strictly above the water on each day. Output Output one single integer β€” the minimum possible sum of the number of marks strictly below the water level among all days. Examples Input 6 0 1 0 3 0 2 Output 6 Input 5 0 1 2 1 2 Output 1 Input 5 0 1 1 2 2 Output 0 Note In the first example, the following figure shows an optimal case. <image> Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6. In the second example, the following figure shows an optimal case. <image>
taco
n = int(input()) a = list(map(int, input().split())) ma = [1] * n for i in range(1, n): ma[i] = max(ma[i - 1], a[i] + 1) for i in range(n - 2, -1, -1): ma[i] = max(ma[i + 1] - 1, ma[i]) print(sum(ma) - sum(a) - n)
python
11
0.481481
35
26
8
Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi. Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day. Input The first line contains a single positive integer n (1 ≀ n ≀ 105) β€” the number of days. The second line contains n space-separated integers m1, m2, ..., mn (0 ≀ mi < i) β€” the number of marks strictly above the water on each day. Output Output one single integer β€” the minimum possible sum of the number of marks strictly below the water level among all days. Examples Input 6 0 1 0 3 0 2 Output 6 Input 5 0 1 2 1 2 Output 1 Input 5 0 1 1 2 2 Output 0 Note In the first example, the following figure shows an optimal case. <image> Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6. In the second example, the following figure shows an optimal case. <image>
taco
n = int(input()) m = list(map(int, input().split())) num = [0 for _ in range(n)] cur = 0 for i in range(n - 1, -1, -1): cur -= 1 alt = m[i] + 1 if cur < alt: cur = alt j = i while j < n and num[j] < cur: num[j] = cur j += 1 else: num[i] = cur print(sum(num) - n - sum(m))
python
11
0.493103
35
17.125
16
Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi. Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day. Input The first line contains a single positive integer n (1 ≀ n ≀ 105) β€” the number of days. The second line contains n space-separated integers m1, m2, ..., mn (0 ≀ mi < i) β€” the number of marks strictly above the water on each day. Output Output one single integer β€” the minimum possible sum of the number of marks strictly below the water level among all days. Examples Input 6 0 1 0 3 0 2 Output 6 Input 5 0 1 2 1 2 Output 1 Input 5 0 1 1 2 2 Output 0 Note In the first example, the following figure shows an optimal case. <image> Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6. In the second example, the following figure shows an optimal case. <image>
taco
N = int(input()) above = list(map(int, input().split())) if N == 1: print(0) quit() required_mark = [0] * N required_mark[N - 2] = above[N - 1] for i in reversed(range(N - 2)): required_mark[i] = max(above[i + 1], required_mark[i + 1] - 1) d = 0 mark = 1 for i in range(1, N): if mark == above[i]: mark += 1 elif mark >= required_mark[i]: d += mark - above[i] - 1 else: d += mark - above[i] mark += 1 print(d)
python
11
0.561321
63
20.2
20
Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi. Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day. Input The first line contains a single positive integer n (1 ≀ n ≀ 105) β€” the number of days. The second line contains n space-separated integers m1, m2, ..., mn (0 ≀ mi < i) β€” the number of marks strictly above the water on each day. Output Output one single integer β€” the minimum possible sum of the number of marks strictly below the water level among all days. Examples Input 6 0 1 0 3 0 2 Output 6 Input 5 0 1 2 1 2 Output 1 Input 5 0 1 1 2 2 Output 0 Note In the first example, the following figure shows an optimal case. <image> Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6. In the second example, the following figure shows an optimal case. <image>
taco
n = int(input()) a = list(map(int, input().strip().split())) s = [0] * n under = 0 for i in range(n): s[i] = a[i] for i in range(1, n): s[i] = max(s[i], s[i - 1]) for i in range(n - 2, 0, -1): if s[i + 1] - s[i] > 1: s[i] = s[i + 1] - 1 for i in range(n): under += max(0, s[i] - a[i]) print(under)
python
13
0.483553
43
20.714286
14
Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi. Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day. Input The first line contains a single positive integer n (1 ≀ n ≀ 105) β€” the number of days. The second line contains n space-separated integers m1, m2, ..., mn (0 ≀ mi < i) β€” the number of marks strictly above the water on each day. Output Output one single integer β€” the minimum possible sum of the number of marks strictly below the water level among all days. Examples Input 6 0 1 0 3 0 2 Output 6 Input 5 0 1 2 1 2 Output 1 Input 5 0 1 1 2 2 Output 0 Note In the first example, the following figure shows an optimal case. <image> Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6. In the second example, the following figure shows an optimal case. <image>
taco
n = int(input()) A = [int(x) for x in input().split()] n = len(A) LB = [0] * n lvl = 0 for i in reversed(range(n)): lvl = max(A[i], lvl) LB[i] = lvl + 1 lvl -= 1 poss = [[1, 1]] for i in range(1, n): (l, h) = poss[-1] a = A[i] l = max(a, l) if a == h: l += 1 poss.append([l, h + 1]) Level = [] for i in range(n): if Level: Level.append(max(Level[-1], LB[i], poss[i][0])) else: Level.append(max(LB[i], poss[i][0])) count = 0 for i in range(n): count += max(1, Level[i] - A[i]) - 1 print(count)
python
13
0.519608
49
17.888889
27
Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi. Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day. Input The first line contains a single positive integer n (1 ≀ n ≀ 105) β€” the number of days. The second line contains n space-separated integers m1, m2, ..., mn (0 ≀ mi < i) β€” the number of marks strictly above the water on each day. Output Output one single integer β€” the minimum possible sum of the number of marks strictly below the water level among all days. Examples Input 6 0 1 0 3 0 2 Output 6 Input 5 0 1 2 1 2 Output 1 Input 5 0 1 1 2 2 Output 0 Note In the first example, the following figure shows an optimal case. <image> Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6. In the second example, the following figure shows an optimal case. <image>
taco
N = int(input()) M = list(map(int, input().split())) T = [0] * N for i in range(1, N): T[i] = max(T[i - 1], M[i] + 1) for i in range(N - 2, -1, -1): T[i] = max(T[i], T[i + 1] - 1, 0) res = sum([max(0, T[i] - M[i] - 1) for i in range(N)]) print(res)
python
11
0.474104
54
26.888889
9
Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi. Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day. Input The first line contains a single positive integer n (1 ≀ n ≀ 105) β€” the number of days. The second line contains n space-separated integers m1, m2, ..., mn (0 ≀ mi < i) β€” the number of marks strictly above the water on each day. Output Output one single integer β€” the minimum possible sum of the number of marks strictly below the water level among all days. Examples Input 6 0 1 0 3 0 2 Output 6 Input 5 0 1 2 1 2 Output 1 Input 5 0 1 1 2 2 Output 0 Note In the first example, the following figure shows an optimal case. <image> Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6. In the second example, the following figure shows an optimal case. <image>
taco
n = int(input()) a = list(map(int, input().split())) ne = n * [0] ned = 1 for i in range(n - 1, -1, -1): if a[i] + 1 > ned: ned = a[i] + 1 ne[i] = ned ned -= 1 ne.append(0) le = 1 o = 0 for i in range(n): o += le - a[i] - 1 if le < ne[i + 1]: le += 1 print(o)
python
11
0.468401
35
14.823529
17
Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi. Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day. Input The first line contains a single positive integer n (1 ≀ n ≀ 105) β€” the number of days. The second line contains n space-separated integers m1, m2, ..., mn (0 ≀ mi < i) β€” the number of marks strictly above the water on each day. Output Output one single integer β€” the minimum possible sum of the number of marks strictly below the water level among all days. Examples Input 6 0 1 0 3 0 2 Output 6 Input 5 0 1 2 1 2 Output 1 Input 5 0 1 1 2 2 Output 0 Note In the first example, the following figure shows an optimal case. <image> Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6. In the second example, the following figure shows an optimal case. <image>
taco
n = int(input()) above = list(map(int, input().split())) total = [x + 1 for x in above] for i in range(0, n - 1)[::-1]: total[i] = max(total[i], total[i + 1] - 1) for i in range(1, n): total[i] = max(total[i], total[i - 1]) below = [t - a - 1 for (t, a) in zip(total, above)] print(sum(below))
python
11
0.560811
51
31.888889
9
Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi. Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day. Input The first line contains a single positive integer n (1 ≀ n ≀ 105) β€” the number of days. The second line contains n space-separated integers m1, m2, ..., mn (0 ≀ mi < i) β€” the number of marks strictly above the water on each day. Output Output one single integer β€” the minimum possible sum of the number of marks strictly below the water level among all days. Examples Input 6 0 1 0 3 0 2 Output 6 Input 5 0 1 2 1 2 Output 1 Input 5 0 1 1 2 2 Output 0 Note In the first example, the following figure shows an optimal case. <image> Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6. In the second example, the following figure shows an optimal case. <image>
taco
from sys import stdin, stdout def rint(): return map(int, stdin.readline().split()) n = int(input()) u = list(rint()) u = [0] + u mark = 0 b = [0] for i in range(1, n + 1): uu = u[i] b.append(i) if uu >= mark: inc = uu - mark + 1 l = len(b) for i in range(inc): b.pop() mark += inc tot = [1 for i in range(n + 1)] for bb in b: tot[bb] = 0 for i in range(1, n + 1): tot[i] = tot[i - 1] + tot[i] ans = 0 for i in range(1, n + 1): ans += tot[i] - u[i] - 1 print(ans)
python
10
0.532091
42
16.888889
27
Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi. Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day. Input The first line contains a single positive integer n (1 ≀ n ≀ 105) β€” the number of days. The second line contains n space-separated integers m1, m2, ..., mn (0 ≀ mi < i) β€” the number of marks strictly above the water on each day. Output Output one single integer β€” the minimum possible sum of the number of marks strictly below the water level among all days. Examples Input 6 0 1 0 3 0 2 Output 6 Input 5 0 1 2 1 2 Output 1 Input 5 0 1 1 2 2 Output 0 Note In the first example, the following figure shows an optimal case. <image> Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6. In the second example, the following figure shows an optimal case. <image>
taco