description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): new_array = [] new_array2 = [] freq_hash = {} for value in A1: freq_hash[value] = freq_hash.get(value, 0) + 1 for value in A2: if freq_hash.get(value, 0) != 0: for i in range(freq_h...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CA...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, arr1, n, arr2, m): d = {} for i in arr1: if i in d: d[i] += 1 else: d[i] = 1 res = [] for i in arr2: if i in d: for j in range(d[i]): res.ap...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): result2 = [] result = [] A1_dict = {} for i in range(len(A1)): if A1[i] not in A1_dict: A1_dict[A1[i]] = 1 else: A1_dict[A1[i]] += 1 for i in range(len(A2)): ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUM...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): d = {} for i in A1: if i not in d: d[i] = 1 else: d[i] += 1 l = [] for i in A2: if i in d: l.extend([i] * d[i]) s = set(A2) k = [...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR RETURN BIN_OP VAR FUNC_CALL VAR ...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): d = {} for i in A1: if i not in d: d[i] = 1 else: d[i] += 1 l = [] for i in A2: if i in d: for _ in range(d[i]): l += [i] ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR LIST VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): hmap = {} for i in range(N): if A1[i] in hmap: hmap[A1[i]] += 1 else: hmap[A1[i]] = 1 ans = [] for i in range(M): if A2[i] in hmap: ans += hmap[A...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR LIST VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR NUM...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): d = {} for i in A1: d[i] = d.get(i, 0) + 1 a1 = set(A1) a2 = set(A2) a = a1.intersection(a2) b = a1 - a B = [] for i in b: B.extend([i] * d[i]) B.sort() ret ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): hashmap1 = {} for j in range(M): if A2[j] not in hashmap1: hashmap1[A2[j]] = 1 else: hashmap1[A2[j]] += 1 A1_dummy = [] hashmap = {} n = 0 for i in range(N):...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, arr1, N, arr2, M): indexHash = {} def getPositionInArr2(a): if a in indexHash: return indexHash[a] return 10**5 + a for i, a in enumerate(arr2): indexHash[a] = i return sorted(arr1, key=getP...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN VAR VAR RETURN BIN_OP BIN_OP NUMBER NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): k = [] l = {} s = {} for i in A2: s[i] = 1 for i in A1: if s.get(i, 0) == 1: l[i] = l.get(i, 0) + 1 else: k.append(i) ans = [] for i in A...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP LIST VAR VAR VAR EXPR...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M, priority=None): sA1 = [] sA2 = [] if N == 0 or N == 1: return A1 if priority == None: priority = {} for i in range(M): if A2[i] not in priority: priority[A2[i...
CLASS_DEF FUNC_DEF NONE ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR NONE ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): freq = {} a = [] temp = 0 for i in A1: freq[i] = freq.get(i, 0) + 1 for j in A2: if j in freq: a.extend(freq[j] * [j]) freq[j] = 0 l = len(a) b = [] ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR LIST VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): count = [0] * (max(A1) + 1) result = [] for num in A1: count[num] += 1 for num in A2: while count[num] > 0: result.append(num) count[num] -= 1 for num in range(len(c...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR NUMBER FOR VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): h = dict() for i in A1: if str(i) in h.keys(): h[str(i)] += 1 else: h.update({str(i): 1}) s_arr = [] for i in A2: flag = False try: f...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR DICT FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR F...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): dict_freq = {} for x in A1: if x in dict_freq: dict_freq[x] += 1 else: dict_freq[x] = 1 result = [] for x in A2: if x in dict_freq: freq = dict_f...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP LIST VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP LIST VAR VAR RETURN VAR
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): d = {} for i in A1: if i in d: d[i] += 1 else: d[i] = 1 ans = [] an = [] arr = set(A1) - set(A2) for i in arr: if i in d: an.exte...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR VAR ASSIGN ...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): dict1 = {} dict2 = {} ans = [] for i in A2: dict1[i] = True for i in A1: if i in dict2: dict2[i] += 1 else: dict2[i] = 1 A1.sort() for i ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): dic1 = {} for i in range(N): if A1[i] in dic1: dic1[A1[i]] += 1 else: dic1[A1[i]] = 1 A1.sort() a = [] for i in range(M): if A2[i] in dic1: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP LIST VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR ...
Given two integer arrays A1[ ] and A2[ ] of size N and M respectively. Sort the first array A1[ ] such that all the relative positions of the elements in the first array are the same as the elements in the second array A2[ ]. See example for better understanding. Note: If elements are repeated in the second array, cons...
class Solution: def relativeSort(self, A1, N, A2, M): def bin(lb, ub, n, l): if lb <= ub: mid = (lb + ub) // 2 if l[mid] == n: return mid elif l[mid] < n: return bin(mid + 1, ub, n, l) else:...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_C...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): arr2.sort() def binarysearch(arr, target): start = 0 end = len(arr) - 1 ans = 0 while start < end: mid = (start + end) // 2 if arr[mid] == target: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR V...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): arr2.sort() ans = [] def lastIndex(num): start, end = 0, len(arr2) - 1 while start <= end: mid = start + (end - start) // 2 if arr2[mid] <= num: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CAL...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, m, arr2, n): arr2.sort() result = [] for i in range(m): left, right = 0, n - 1 while left <= right: mid = left + (right - left) // 2 if arr2[mid] > arr1[i]: ri...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def binarysearch(self, arr2, n2, x): ans = -1 low = 0 high = n2 - 1 while low <= high: mid = (low + high) // 2 if arr2[mid] <= x: ans = mid low = mid + 1 elif arr2[mid] > x: high = mi...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FU...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): arr = arr1.copy() arr1.sort() arr2.sort() dic = {} ans = [] prev = 0 i = 0 for elm in arr1: count = 0 while i < n2: if arr2[i] <= elm: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR VAR VAR
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, a1, n1, a2, n2): a2.sort() ans = [] for i in range(n1): low = 0 high = n2 - 1 mid = (high + low) // 2 if a1[i] >= a2[high]: ans.append(n2) elif a1[i] < a2[low]: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR ...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): r = [n2] * n1 arr2.sort() for i in range(n1): l = 0 h = n2 - 1 while l <= h: m = (l + h) // 2 if arr2[m] > arr1[i]: r[i] = m ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VA...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): arr2.sort() def search(x): low = 0 high = len(arr2) while low < high: mid = low + (high - low) // 2 if arr2[mid] < x: low = mid + 1 ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): def search(arr, i): first = 0 last = len(arr) - 1 while first <= last: mid = (first + last) // 2 if arr[mid] == i: first = mid + 1 ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR ...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def upper_bound(self, arr, n, x): l = 0 h = n - 1 while l < h: m = l + (h - l) // 2 if arr[m] <= x: l = m + 1 else: h = m if arr[h] > x: return h if arr[l] > x: return...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VA...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): ans = [] arr2.sort() for i in range(n1): count = 0 s = 0 e = n2 - 1 mid = 0 while s <= e: mid = (s + e) // 2 if arr2[mid] <= arr...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RET...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): def bin(arr, n, x): s = 0 s1 = n - 1 while s <= s1: mid = s + (s1 - s) // 2 if arr[mid] <= x: s = mid + 1 else: ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VA...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): arr = arr1.copy() arr1.sort() arr2.sort() d = {} c = j = 0 for i in arr1: while j < n2: if arr2[j] > i: break c += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER FOR VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): res = [] arr2.sort() def binary(target, n2): low = 0 high = n2 - 1 ans = 0 while low <= high: mid = low + (high - low) // 2 if arr2[mid] > ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
def mgc(arr, x): st, en = 0, len(arr) - 1 ans = len(arr) while st <= en: mid = (st + en) // 2 if arr[mid] > x: ans = mid en = mid - 1 else: st = mid + 1 if x == len(arr) and arr[0] > x: return 0 return ans class Solution: def...
FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER VAR RETURN NUMBER RETURN VAR CLASS_DEF FUNC_DEF EX...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): ans = [0] * n1 arr2.sort() for i in range(n1): temp = 0 low = 0 high = n2 - 1 while low <= high: mid = (low + high) // 2 if arr2[mid] <= arr...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN V...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
def mgc(arr, x): st, en = 0, len(arr) - 1 ans = len(arr) while st <= en: mid = (st + en) // 2 if arr[mid] > x: ans = mid en = mid - 1 else: st = mid + 1 return ans class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): ...
FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL V...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): arr2.sort() result = [] for x in arr1: index = self.binarySearch(arr2, n2, x) result.append(index) return result def binarySearch(self, arr, n, x): left, right = 0, n - 1 ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUM...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): m = [] l = [0] * (max(max(arr1), max(arr2)) + 1) for ele in arr2: l[ele] += 1 p = [] p.append(l[0]) for i in range(1, len(l)): p.append(p[i - 1] + l[i]) for ele in ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR VAR EXP...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): arr2.sort() ar = [] for i in arr1: l = 0 u = n2 - 1 ind = n2 while l <= u: m = (l + u) // 2 if arr2[m] > i: u = m - 1 ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): copy = arr1[:] arr1.sort() arr2.sort() prev_count = 0 res = {} j = 0 for i in arr1: curr_count = 0 while j < len(arr2): if arr2[j] <= i: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VA...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def binary(self, k, arr2, end): start = 0 ans = -1 while start <= end: mid = start + (end - start) // 2 if arr2[mid] <= k: ans = mid start = mid + 1 else: end = mid - 1 return ans + 1...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): res = [0] * n1 arr2.sort() for i in range(n1): s = 0 e = n2 - 1 if n2 == 1: if arr1[i] >= arr2[0]: res[i] = 1 else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR ...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def Just_smaller(self, arr2, n, val): start = 0 end = n - 1 mx = -1 while start <= end: middle = (start + end) // 2 if arr2[middle] <= val: mx = middle start = middle + 1 else: end = ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FU...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): arr2.sort() mini = arr2[0] maxi = arr2[n2 - 1] for i in range(n1): if arr1[i] < mini: arr1[i] = 0 elif arr1[i] > maxi: arr1[i] = n2 else: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): arr2.sort() for i in range(n1): key = arr1[i] l, h = 0, n2 - 1 index = -1 while l <= h: mid = (l + h) // 2 if arr2[mid] <= arr1[i]: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): arr2.sort() def check(arr2, n2, i): low = 0 high = n2 - 1 while low <= high: mid = (low + high) // 2 if arr2[mid] >= i: high = mid - 1 ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP ...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def solve(self, nums, target): l = 0 r = len(nums) - 1 san = len(nums) while l <= r: mid = (l + r) // 2 if nums[mid] <= target: l = mid + 1 else: r = mid - 1 san = mid else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR VAR EX...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): s, sm_till, mx = 0, [], max(max(arr1), max(arr2)) freq = [0] * (mx + 1) for elem in arr2: freq[elem] += 1 for elem in freq: s += elem sm_till.append(s) return [sm_till[...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR VAR VAR VAR
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def binsearch(self, arr, k, n): s = 0 e = n - 1 res = -1 while s <= e: m = (s + e) // 2 if arr[m] == k: res = m s = m + 1 if arr[m] < k: res = m s = m + 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): l = [] m = max(arr2) temp = [(0) for i in range(m + 1)] for i in arr2: temp[i] += 1 for i in range(1, m + 1): temp[i] += temp[i - 1] for i in arr1: if i < m + 1...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER RETU...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, array1, n1, array2, n2): n1_size = max(array1) n2_size = max(array2) holder = [(0) for i in range(max(n1_size, n2_size) + 1)] for i in array2: holder[i] += 1 count = 0 for i in range(len(holder)): ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR ...
Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[]. Example 1: Input: m = 6, n = 6 arr1[] = {1,2,3,4,7,9} arr2[] = {0,1,2,1,1,4} Output: 4 5 5 6 6 6 Explanation: Number of elements less than or equal to 1, 2, 3, 4,...
class Solution: def countEleLessThanOrEqual(self, arr1, n1, arr2, n2): k = [] for i in arr1: k.append(i) arr1.sort() arr2.sort() d = {} j = 0 v = [] for i in range(n1): while j < n2 and arr2[j] <= arr1[i]: j += ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef has failed miserably in several cooking competitions, which makes him think that he's been out of luck recently. Therefore, he decided to build a magic circle using his N chopsticks (numbered 1 through N), hoping that it would ...
T = int(input()) for t in range(T): N, L, U = map(int, input().split()) arr = sorted(list(map(int, input().split()))) mini = maxi = arr[-1] pref = min(L, arr[-1]) cnt, mod = 0, [] for i in range(N - 2, -1, -1): mini = max(mini, pref + arr[i]) pref = min(pref + L, mini) if...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER LIST FOR VAR FUNC_CALL VA...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() i = 0 j = 0 k = 0 m = 1000000000 ans = [0, 0, 0] while i < n and k < n and j < n: temp = [a[i], b[j], c[k]] if m > max(temp) - ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() i_a = 0 i_b = 0 i_c = 0 min_diff_triplet = [-1] * 3 min_diff = 10**5 for x in range(3 * (n - 1) + 1): val_a, val_b, val_c = a[i_a], b[i_b],...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() difference = float("inf") p1, p2, p3 = 0, 0, 0 x, y, z = 0, 0, 0 while p1 < n and p2 < n and p3 < n: mn = min(a[p1], b[p2], c[p3]) mx = max(a[p...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSI...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() i, j, k = 0, 0, 0 op = [i for i in range(3)] minDiff = float("INF") while i < n and j < n and k < n: mi = min(a[i], b[j], c[k]) ma = max(a[i], ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSI...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() i, j, k = 0, 0, 0 mini = 100000000.0 while i < n and j < n and k < n: sum = a[i] + b[j] + c[k] mn = min(a[i], b[j], c[k]) mx = max(a[i], b[...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VA...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): def minimum(x, y, z): return min(min(x, y), z) def maximum(x, y, z): return max(max(x, y), z) res_min, res_max, res_mid = 0, 0, 0 a.sort() b.sort() c.sort() i, j, k = ...
CLASS_DEF FUNC_DEF FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR VAR VA...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() i, j, k = 0, 0, 0 diff = 99999 while i < n and j < n and k < n: maxele = max(a[i], max(b[j], c[k])) minele = min(a[i], min(b[j], c[k])) if ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN V...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
import sys class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() i = j = k = 0 rdiff = rsum = sys.maxsize while i < n and j < n and k < n: maxnum = max(a[i], b[j], c[k]) minnum = min(a[i], b[j], c[k]) ...
IMPORT CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() i, j, k = 0, 0, 0 diff = 99999 while i < n and j < n and k < n: ma = max(a[i], b[j], c[k]) mi = min(a[i], b[j], c[k]) if ma - mi < diff: ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() i = 0 j = 0 k = 0 minm = float("inf") while i < n and j < n and k < n: triplet = [a[i], b[j], c[k]] currMin = min(triplet) ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF V...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
def maximum(a, b, c): return max(max(a, b), c) def minimum(a, b, c): return min(min(a, b), c) class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() i, j, k = 0, 0, 0 res_min, res_max, res_mid = 0, 0, 0 diff = 99999999...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSI...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort(reverse=True) b.sort(reverse=True) c.sort(reverse=True) triplet = [0, 0, 0] diff = float("inf") while a and b and c: arr = [a[-1], b[-1], c[-1]] maxi = max(arr) ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR VAR ASSIGN VAR LIST VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN ...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() result1 = 0 result2 = 0 result3 = 0 i = 0 j = 0 k = 0 diff = 100000 while i < n and j < n and k < n: sum = a[i] + b[j] + c[...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VA...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): x = y = z = p = q = r = 0 a.sort() b.sort() c.sort() diff = 100000 while p < n and q < n and r < n: mn = min(a[p], b[q], c[r]) mx = max(a[p], b[q], c[r]) d = mx - mn ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN V...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def maximum(self, a, b, c): return max(max(a, b), c) def minimum(self, a, b, c): return min(min(a, b), c) def smallestDifferenceTriplet(self, arr1, arr2, arr3, n): arr1.sort() arr2.sort() arr3.sort() res_min = 0 res_max = 0 r...
CLASS_DEF FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE ...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): i, j, k = 0, 0, 0 prev_diff = None prev_sum = None a.sort() b.sort() c.sort() while i < n and j < n and k < n: tmp_a = a[i] tmp_b = b[j] tmp_c = c[k] ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NONE ASSIGN VAR NONE EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR ...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
import sys class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() x, y, z = a[0], b[0], c[0] res = sys.maxsize i, j, k = 0, 0, 0 while i < n and j < n and k < n: mini, maxi = min(a[i], b[j], c[k]), max(a[i], ...
IMPORT CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VA...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
import sys class Solution: def smallestDifferenceTriplet(self, a, b, c, n): diff = sys.maxsize a.sort() b.sort() c.sort() ans = [] i = j = k = 0 while i < n and j < n and k < n: mini = min(a[i], b[j], c[k]) maxi = max(a[i], b[j], c[k...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF ...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() ma = float("inf") i, j, k = 0, 0, 0 while i < n and j < n and k < n: mi = min(a[i], b[j], c[k]) diff = max(a[i], b[j], c[k]) - mi if diff <...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR LIST VAR VA...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def binarysearch(self, arr, l, r, k): if l <= r: mid = (l + r) // 2 if arr[mid] <= k: return self.binarysearch(arr, mid + 1, r, k) else: return self.binarysearch(arr, l, mid - 1, k) return r def smallestDiffere...
CLASS_DEF FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() i, j, k = 0, 0, 0 I, J, K = -1, -1, -1 m = max(a[-1], b[-1], c[-1]) - min(a[0], b[0], c[0]) while i < n and j < n and k < n: temp = max(a[i], b[j], c[k]) -...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() i = 0 j = 0 k = 0 diff = 99999999999999 while i < n and j < n and k < n: sum1 = sum([a[i], b[j], c[k]]) min1 = min([a[i], b[j], c[k]]) ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR ...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
import sys class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() l1 = l2 = l3 = 0 sum = 0 diff = sys.maxsize maxi = 0 mini = 0 res_sum = a[0] + b[0] + c[0] res_max = 0 res_min = 0 ...
IMPORT CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a, b, c = sorted(a), sorted(b), sorted(c) i, j, k = 0, 0, 0 p, q, r = 0, 0, 0 sum, diff = 0, 123456789 while i < n and j < n and k < n: csum = a[i] + b[j] + c[k] maximum = max(a[i], b[j]...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): merge_sort(a) merge_sort(b) merge_sort(c) i = 0 j = 0 k = 0 diff = 100000000000 temmax = 0 temmin = 0 temmid = 0 while i < n and j < n and k < n: summ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VA...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() results = [] sums = [] diff = max(a[0], b[0], c[0]) - min(a[0], b[0], c[0]) i = 0 j = 0 k = 0 while i < n and j < n and k < n: mini...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def func(x, y, z): mn = min(x, y, z) mx = max(x, y, z) return mx - mn def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() i, j, k = 0, 0, 0 a1, b1, c1 = a[-1], b[-1], c[-1] ans = 1000000 whi...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): minDiff = float("inf") first, second, third = 0, 0, 0 a.sort() b.sort() c.sort() ans = [] while first < n and second < n and third < n: mini = min(a[first], b[second], c[third]) ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): res = [] a.sort() b.sort() c.sort() i, j, k = 0, 0, 0 fi, fj, fk = 0, 0, 0 diff = 99999999 while i < n and j < n and k < n: mn = min(a[i], b[j], c[k]) mx = max(a[...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR AS...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() ans = float("inf") p1 = p2 = p3 = 0 res1 = res2 = res3 = 0 while p1 < len(a) and p2 < len(b) and p3 < len(c): maxx = max(a[p1], b[p2], c[p3]) m...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VA...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() i = j = k = 0 p = q = r = 0 summ = a[0] + b[0] + c[0] diff = max(a[p], b[q], c[r]) - min(a[p], b[q], c[r]) while i < n and j < n and k < n: maxi = ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, Arr1, Arr2, Arr3, N): ans = [] Arr1.sort() Arr2.sort() Arr3.sort() maxo, mino, mido = 0, 0, 0 i, j, k = 0, 0, 0 maxoo, minoo, midoo = 0, 0, 0 diff = 1000001 ludo = 0 non = 0 w...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() i = j = k = 0 num1 = num2 = num3 = 0 diff = float("inf") while i < len(a) and j < len(b) and k < len(c): min_val = min(a[i], b[j], c[k]) max_va...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VA...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, a, b, c, n): a.sort() b.sort() c.sort() i, j, k = 0, 0, 0 temp = [a[i], b[j], c[k]] val = 1000000 ans = [] while i < n and j < n and k < n: temp = [a[i], b[j], c[k]] mi, ma = ...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NU...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
import sys class Solution: def smallestDifferenceTriplet(self, arr1, arr2, arr3, n): arr1.sort() arr2.sort() arr3.sort() t1, t2, t3 = 0, 0, 0 i, j, k = 0, 0, 0 diff = 1000000 while i < n and j < n and k < n: sum = arr1[i] + arr2[j] + arr3[k] ...
IMPORT CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR V...
Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the...
class Solution: def smallestDifferenceTriplet(self, A, B, C, n): i, j, k = 0, 0, 0 A.sort() B.sort() C.sort() nA = len(A) nB = len(B) nC = len(C) ans = 2147483647 diff = 2147483647 while i < nA and j < nB and k < nC: a = A[...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VA...
Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the K^{th} smallest element in the given array. It is given that all array elements are distinct. Note :- l and r denotes the starting and ending index of the array. Example 1: Input: N = 6 arr[] = 7 10 4 3 20 15 K = 3 Out...
class Solution: def kthSmallest(self, arr, l, r, k): def partition(arr, l, r): pivot = arr[r] i = l - 1 for j in range(l, r): if arr[j] <= pivot: i += 1 arr[i], arr[j] = arr[j], arr[i] arr[i + 1], arr[r...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ...
Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the K^{th} smallest element in the given array. It is given that all array elements are distinct. Note :- l and r denotes the starting and ending index of the array. Example 1: Input: N = 6 arr[] = 7 10 4 3 20 15 K = 3 Out...
import sys sys.setrecursionlimit(10**8) class Solution: def swap(self, arr, a, b): temp = arr[a] arr[a] = arr[b] arr[b] = temp def randomPartition(self, arr, l, r): n = r - l + 1 pivot = int(random.random() % n) self.swap(arr, l + pivot, r) return sel...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR NUM...
Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the K^{th} smallest element in the given array. It is given that all array elements are distinct. Note :- l and r denotes the starting and ending index of the array. Example 1: Input: N = 6 arr[] = 7 10 4 3 20 15 K = 3 Out...
class Solution: def kthSmallest(self, arr, l, r, k): arr.sort() count = 0 for i in range(len(arr)): count += 1 if count == k: return arr[i]
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR RETURN VAR VAR
Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the K^{th} smallest element in the given array. It is given that all array elements are distinct. Note :- l and r denotes the starting and ending index of the array. Example 1: Input: N = 6 arr[] = 7 10 4 3 20 15 K = 3 Out...
class Solution: def kthSmallest(self, arr, l, r, k): if k > 0 and k <= r - l + 1: pos = partition(arr, l, r) if pos - l == k - 1: return arr[pos] elif pos - l > k - 1: return self.kthSmallest(arr, l, pos - 1, k) else: ...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR...
Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the K^{th} smallest element in the given array. It is given that all array elements are distinct. Note :- l and r denotes the starting and ending index of the array. Example 1: Input: N = 6 arr[] = 7 10 4 3 20 15 K = 3 Out...
class Solution: def kthSmallest(self, arr, l, r, k): counting = [0] * (10**5 + 1) for i in arr: counting[i] += 1 count = 0 for i in range(10**5 + 1): count += counting[i] if count >= k: return i
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR VAR VAR IF VAR VAR RETURN VAR
Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the K^{th} smallest element in the given array. It is given that all array elements are distinct. Note :- l and r denotes the starting and ending index of the array. Example 1: Input: N = 6 arr[] = 7 10 4 3 20 15 K = 3 Out...
class Solution: def partionAlgo(self, arr, pivot, low, right): i = low j = low while i <= right: if arr[i] > pivot: i += 1 else: arr[i], arr[j] = arr[j], arr[i] i += 1 j += 1 return arr.index(piv...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER R...
Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the K^{th} smallest element in the given array. It is given that all array elements are distinct. Note :- l and r denotes the starting and ending index of the array. Example 1: Input: N = 6 arr[] = 7 10 4 3 20 15 K = 3 Out...
class Solution: def kthSmallest(self, arr, l, r, k): d = {} for ele in arr: d[ele] = d.get(ele, 0) + 1 n = 0 for ele in sorted(d.keys()): n += d[ele] if n == k: return ele
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR RETURN VAR
Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the K^{th} smallest element in the given array. It is given that all array elements are distinct. Note :- l and r denotes the starting and ending index of the array. Example 1: Input: N = 6 arr[] = 7 10 4 3 20 15 K = 3 Out...
class Solution: def partition(self, arr, l, r): x = arr[r] i = l for j in range(l, r): if arr[j] <= x: arr[i], arr[j] = arr[j], arr[i] i += 1 arr[i], arr[r] = arr[r], arr[i] return i def kthSmallest(self, arr, l, r, k): ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR ...
Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the K^{th} smallest element in the given array. It is given that all array elements are distinct. Note :- l and r denotes the starting and ending index of the array. Example 1: Input: N = 6 arr[] = 7 10 4 3 20 15 K = 3 Out...
class Solution: def kthSmallest(self, arr, l, r, k): def fun(arr, l, r, k): if l == r: return arr[k] else: i = l ele = arr[l] for j in range(l + 1, r + 1): if arr[j] <= ele: ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR RETURN VAR VAR IF VAR VAR RETURN FUNC_CALL V...
Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the K^{th} smallest element in the given array. It is given that all array elements are distinct. Note :- l and r denotes the starting and ending index of the array. Example 1: Input: N = 6 arr[] = 7 10 4 3 20 15 K = 3 Out...
class Solution: def kthSmallest(self, arr, l, r, k): l = min(arr) h = max(arr) ans = -1 while l <= h: mid = l + (h - l) // 2 csm = self.countSmaller(arr, mid) if csm >= k - 1: ans = mid h = mid - 1 else:...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR RETU...
Given an array arr[] and an integer K where K is smaller than size of array, the task is to find the K^{th} smallest element in the given array. It is given that all array elements are distinct. Note :- l and r denotes the starting and ending index of the array. Example 1: Input: N = 6 arr[] = 7 10 4 3 20 15 K = 3 Out...
class Solution: def kthSmallest(self, arr, l, r, k): if l == 0 and r == len(arr) - 1: k -= 1 if l == r: return arr[k] else: i = l ele = arr[l] for j in range(l + 1, r + 1): if arr[j] <= ele: i +=...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR IF ...