text stringlengths 17 3.65k | code stringlengths 70 5.84k |
|---|---|
Check if two sorted arrays can be merged to form a sorted array with no adjacent pair from the same array | Function to check if it is possible to merge the two given arrays with given conditions ; Stores index of the array A [ ] ; Stores index of the array B [ ] ; Check if the previous element are from the array A [ ]... | def checkIfPossibleMerge ( A , B , N ) : NEW_LINE INDENT i = 0 NEW_LINE j = 0 NEW_LINE prev = - 1 NEW_LINE flag = 1 NEW_LINE while ( i < N and j < N ) : NEW_LINE INDENT if ( A [ i ] < B [ j ] and prev != 0 ) : NEW_LINE INDENT prev = 0 NEW_LINE i += 1 NEW_LINE DEDENT elif ( B [ j ] < A [ i ] and prev != 1 ) : NEW_LINE I... |
Minimize array sum by replacing greater and smaller elements of pairs by half and double of their values respectively atmost K times | Function to find the minimum sum of array elements by given operations ; Base case ; Return 0 ; Base case ; Perform K operations ; Stores smallest element in the array ; Stores index of... | def minimum_possible_sum ( arr , n , k ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( n == 1 ) : NEW_LINE INDENT return arr [ 0 ] NEW_LINE DEDENT for i in range ( k ) : NEW_LINE INDENT smallest_element = arr [ 0 ] NEW_LINE smallest_pos = 0 NEW_LINE largest_element = arr [ 0 ] NEW_LINE... |
Rearrange array elements excluded by given ranges to maximize sum of subarrays starting from the first index | Function that finds the maximum sum all subarrays from the starting index after rearranging the array ; Stores elements after rearranging ; Keeps track of visited elements ; Traverse the queries ; Mark element... | def maxSum ( n , a , l , q ) : NEW_LINE INDENT v = [ ] NEW_LINE d = [ 0 ] * n NEW_LINE for i in range ( q ) : NEW_LINE INDENT for x in range ( l [ i ] [ 0 ] , l [ i ] [ 1 ] + 1 ) : NEW_LINE INDENT if ( d [ x ] == 0 ) : NEW_LINE INDENT d [ x ] = 1 NEW_LINE DEDENT DEDENT DEDENT st = set ( [ ] ) NEW_LINE for i in range ( ... |
Count pairs with Bitwise XOR greater than both the elements of the pair | Python3 program for the above approach ; Function to count pairs whose XOR is greater than the pair itself ; Stores the count of pairs ; Sort the array ; Traverse the array ; If current element is 0 , then ignore it ; Traverse all the bits of ele... | import math NEW_LINE def countPairs ( A , N ) : NEW_LINE INDENT count = 0 NEW_LINE A . sort ( ) NEW_LINE bits = [ 0 ] * 32 NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT if ( A [ i ] == 0 ) : NEW_LINE INDENT continue NEW_LINE DEDENT for j in range ( 0 , 32 ) : NEW_LINE INDENT if ( ( ( 1 << j ) & A [ i ] ) == 0 ) :... |
Maximum occurred integers after M circular operations in given range | Function to find the maximum occurred integer after completing all circular operations ; Stores the highest visit count for any element ; Stors the number of times an element is visited ; Iterate over the array ; Iterate over the range circularly fo... | def mostvisitedsector ( N , A ) : NEW_LINE INDENT maxVisited = 0 NEW_LINE mp = { } NEW_LINE for i in range ( 0 , len ( A ) - 1 ) : NEW_LINE INDENT start = A [ i ] % N NEW_LINE end = A [ i + 1 ] % N NEW_LINE while ( start != end ) : NEW_LINE INDENT if ( start == 0 ) : NEW_LINE INDENT if N in mp : NEW_LINE INDENT mp [ N ... |
Area of the largest rectangle formed by lines parallel to X and Y axis from given set of points | Function to return the area of the largest rectangle formed by lines parallel to X and Y axis from given set of points ; Initialize two arrays ; Store x and y coordinates ; Sort arrays ; Initialize max differences ; Find m... | def maxRectangle ( sequence , size ) : NEW_LINE INDENT X_Cord = [ 0 ] * size NEW_LINE Y_Cord = [ 0 ] * size NEW_LINE for i in range ( size ) : NEW_LINE INDENT X_Cord [ i ] = sequence [ i ] [ 0 ] NEW_LINE Y_Cord [ i ] = sequence [ i ] [ 1 ] NEW_LINE DEDENT X_Cord . sort ( ) NEW_LINE Y_Cord . sort ( ) NEW_LINE X_Max = 0 ... |
Rearrange two given arrays such that sum of same indexed elements lies within given range | Function to check if there exists any arrangements of the arrays such that sum of element lie in the range [ K / 2 , K ] ; Sort the array arr1 [ ] in increasing order ; Sort the array arr2 [ ] in decreasing order ; Traverse the ... | def checkArrangement ( A1 , A2 , n , k ) : NEW_LINE INDENT A1 = sorted ( A1 ) NEW_LINE A2 = sorted ( A2 ) NEW_LINE A2 = A2 [ : : - 1 ] NEW_LINE flag = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( ( A1 [ i ] + A2 [ i ] > k ) or ( A1 [ i ] + A2 [ i ] < k // 2 ) ) : NEW_LINE INDENT flag = 1 NEW_LINE break NEW_LI... |
Rearrange two given arrays to maximize sum of same indexed elements | Function to find the maximum possible sum by rearranging the given array elements ; Sort the array A [ ] in ascending order ; Sort the array B [ ] in descending order ; Stores maximum possible sum by rearranging array elements ; Traverse both the arr... | def MaxRearrngeSum ( A , B , N ) : NEW_LINE INDENT A . sort ( ) NEW_LINE B . sort ( reverse = True ) NEW_LINE maxSum = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT maxSum += abs ( A [ i ] - B [ i ] ) NEW_LINE DEDENT return maxSum NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = [ 1 , 2 , 2 , 4... |
Area of the largest rectangle possible from given coordinates | Function to find the maximum possible area of a rectangle ; Initialize variables ; Sort array arr1 [ ] ; Sort array arr2 [ ] ; Traverse arr1 [ ] and arr2 [ ] ; If arr1 [ i ] is same as arr2 [ j ] ; If no starting point is found yet ; Update maximum end ; I... | def largestArea ( arr1 , n , arr2 , m ) : NEW_LINE INDENT end = 0 NEW_LINE start = 0 NEW_LINE i = 0 NEW_LINE j = 0 NEW_LINE arr1 . sort ( reverse = False ) NEW_LINE arr2 . sort ( reverse = False ) NEW_LINE while ( i < n and j < m ) : NEW_LINE INDENT if ( arr1 [ i ] == arr2 [ j ] ) : NEW_LINE INDENT if ( start == 0 ) : ... |
Count pairs from two arrays with difference exceeding K | Function to count pairs that satisfy the given conditions ; Stores index of the left pointer . ; Stores index of the right pointer ; Stores count of total pairs that satisfy the conditions ; Sort arr [ ] array ; Sort brr [ ] array ; Traverse both the array and c... | def count_pairs ( arr , brr , N , M , K ) : NEW_LINE INDENT i = 0 NEW_LINE j = 0 NEW_LINE cntPairs = 0 NEW_LINE arr = sorted ( arr ) NEW_LINE brr = sorted ( brr ) NEW_LINE while ( i < N and j < M ) : NEW_LINE INDENT if ( brr [ j ] - arr [ i ] > K ) : NEW_LINE INDENT cntPairs += ( M - j ) NEW_LINE i += 1 NEW_LINE DEDENT... |
Merge two sorted arrays in O ( 1 ) extra space using Heap | Function to perform min heapify on array brr [ ] ; Stores index of left child of i . ; Stores index of right child of i . ; Stores index of the smallest element in ( arr [ i ] , arr [ left ] , arr [ right ] ) ; Check if arr [ left ] less than arr [ smallest ] ... | def minHeapify ( brr , i , M ) : NEW_LINE INDENT left = 2 * i + 1 NEW_LINE right = 2 * i + 2 NEW_LINE smallest = i NEW_LINE if ( left < M and brr [ left ] < brr [ smallest ] ) : NEW_LINE INDENT smallest = left NEW_LINE DEDENT if ( right < M and brr [ right ] < brr [ smallest ] ) : NEW_LINE INDENT smallest = right NEW_L... |
Merge two sorted arrays in O ( 1 ) extra space using QuickSort partition | Function to perform the partition around the pivot element ; Stores index of each element of the array , arr [ ] ; Stores index of each element of the array , brr [ ] ; Traverse both the array ; If pivot is smaller than arr [ l ] ; If Pivot is g... | def partition ( arr , N , brr , M , Pivot ) : NEW_LINE INDENT l = N - 1 NEW_LINE r = 0 NEW_LINE while ( l >= 0 and r < M ) : NEW_LINE INDENT if ( arr [ l ] < Pivot ) : NEW_LINE INDENT l -= 1 NEW_LINE DEDENT elif ( brr [ r ] > Pivot ) : NEW_LINE INDENT r += 1 NEW_LINE DEDENT else : NEW_LINE INDENT arr [ l ] , brr [ r ] ... |
Count array elements with rank not exceeding K | Function to find count of array elements with rank less than or equal to k ; Initialize rank and position ; Sort the given array ; Traverse array from right to left ; Update rank with position , if adjacent elements are unequal ; Return position - 1 , if rank greater tha... | def rankLessThanK ( arr , k , n ) : NEW_LINE INDENT rank = 1 ; NEW_LINE position = 1 ; NEW_LINE arr = sorted ( arr ) NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( i == n - 1 or arr [ i ] != arr [ i + 1 ] ) : NEW_LINE INDENT rank = position ; NEW_LINE if ( rank > k ) : NEW_LINE INDENT return posit... |
Remove Sub | Function to remove sub - directories from the given lists dir ; Store final result ; Sort the given directories ; Insert 1 st directory ; Iterating in directory ; Current directory ; Our previous valid directory ; Find length of previous directory ; If subdirectory is found ; Else store it in result valid ... | def eraseSubdirectory ( dir ) : NEW_LINE INDENT res = [ ] NEW_LINE dir . sort ( ) NEW_LINE res . append ( dir [ 0 ] ) NEW_LINE print ( " { " , dir [ 0 ] , end = " , β " ) NEW_LINE for i in range ( 1 , len ( dir ) ) : NEW_LINE INDENT curr = dir [ i ] NEW_LINE prev = res [ len ( res ) - 1 ] NEW_LINE l = len ( prev ) NEW_... |
Maximize count of pairs ( i , j ) from two arrays having element from first array not exceeding that from second array | Function to return the maximum number of required pairs ; Max Heap to add values of arr2 [ ] ; Sort the array arr1 [ ] ; Push all arr2 [ ] into Max Heap ; Initialize the ans ; Traverse the arr1 [ ] i... | def numberOfPairs ( arr1 , n , arr2 , m ) : NEW_LINE INDENT pq = [ ] NEW_LINE arr1 . sort ( reverse = False ) NEW_LINE for j in range ( m ) : NEW_LINE INDENT pq . append ( arr2 [ j ] ) NEW_LINE DEDENT ans = 2 NEW_LINE i = n - 1 NEW_LINE while ( i >= 0 ) : NEW_LINE INDENT pq . sort ( reverse = False ) NEW_LINE if ( pq [... |
Minimum number of operations to convert a given sequence into a Geometric Progression | Set 2 | Python3 program for above approach ; Function to find minimum cost ; Sort the array ; Maximum possible common ratios ; Iterate over all possible common ratios ; Calculate operations required for the current common ratio ; Ca... | import sys NEW_LINE def minCost ( arr , n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT print ( 0 ) NEW_LINE return NEW_LINE DEDENT arr = sorted ( arr ) NEW_LINE raised = 1 / ( n - 1 ) NEW_LINE temp = pow ( arr [ n - 1 ] , raised ) NEW_LINE r = round ( temp ) + 1 NEW_LINE min_cost = sys . maxsize NEW_LINE common_... |
Mth bit in Nth binary string from a sequence generated by the given operations | Python3 program for above approach ; Function to calculate N Fibonacci numbers ; Function to find the mth bit in the string Sn ; Base case ; Length of left half ; Length of the right half ; Recursive check in the left half ; Recursive chec... | maxN = 10 NEW_LINE def calculateFib ( fib , n ) : NEW_LINE INDENT fib [ 0 ] = fib [ 1 ] = 1 NEW_LINE for x in range ( 2 , n ) : NEW_LINE INDENT fib [ x ] = ( fib [ x - 1 ] + fib [ x - 2 ] ) NEW_LINE DEDENT DEDENT def find_mth_bit ( n , m , fib ) : NEW_LINE INDENT if ( n <= 1 ) : NEW_LINE INDENT return n NEW_LINE DEDENT... |
Minimize count of adjacent row swaps to convert given Matrix to a Lower Triangular Matrix | Function to count the minimum number of adjacent swaps ; Stores the size of the given matrix ; Stores the count of zero at the end of each row ; Traverse the given matrix ; Count of 0 s at the end of the ith row ; Stores the cou... | def minAdjSwaps ( mat ) : NEW_LINE INDENT N = len ( mat ) NEW_LINE cntZero = [ 0 ] * ( N ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N - 1 , - 1 , - 1 ) : NEW_LINE INDENT if mat [ i ] [ j ] != 0 : NEW_LINE INDENT break NEW_LINE DEDENT cntZero [ i ] += 1 NEW_LINE DEDENT DEDENT cntSwaps = 0 NEW_LIN... |
Largest area in a grid unbounded by towers | Function to calculate the largest area unguarded by towers ; Sort the x - coordinates of the list ; Sort the y - coordinates of the list ; dx -- > maximum uncovered tiles in x coordinates ; dy -- > maximum uncovered tiles in y coordinates ; Calculate the maximum uncovered di... | def maxArea ( point_x , point_y , n , length , width ) : NEW_LINE INDENT point_x . sort ( ) NEW_LINE point_y . sort ( ) NEW_LINE dx = point_x [ 0 ] NEW_LINE dy = point_y [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT dx = max ( dx , point_x [ i ] - point_x [ i - 1 ] ) NEW_LINE dy = max ( dy , point_y [ i ] -... |
Split an Array to maximize subarrays having equal count of odd and even elements for a cost not exceeding K | Function to find the cost of splitting the arrays into subarray with cost less than K ; Store the possible splits ; Stores the cost of each split ; Stores the count of even numbers ; Stores the count of odd num... | def make_cuts ( arr , n , K ) : NEW_LINE INDENT ans = 0 NEW_LINE poss = [ ] NEW_LINE ce = 0 NEW_LINE co = 0 NEW_LINE for x in range ( n - 1 ) : NEW_LINE INDENT if ( arr [ x ] % 2 == 0 ) : NEW_LINE INDENT ce += 1 NEW_LINE DEDENT else : NEW_LINE INDENT co += 1 NEW_LINE DEDENT if ( ce == co and co > 0 and ce > 0 ) : NEW_L... |
Cost of rearranging the array such that no element exceeds the sum of its adjacent elements | Function to check if given elements can be arranged such that sum of its neighbours is strictly greater ; Initialize the total cost ; Storing the original index of elements in a hashmap ; Sort the given array ; Check if a give... | def Arrange ( arr , n ) : NEW_LINE INDENT cost = 0 NEW_LINE index = { } NEW_LINE for i in range ( n ) : NEW_LINE INDENT index [ arr [ i ] ] = i NEW_LINE DEDENT arr . sort ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( i == 0 ) : NEW_LINE INDENT if ( arr [ i ] > arr [ i + 1 ] + arr [ - 1 ] ) : NEW_LINE INDENT ... |
XOR of all possible pairwise sum from two given Arrays | Function to calculate the sum of XOR of the sum of every pair ; Stores the XOR of sums of every pair ; Iterate to generate all possible pairs ; Update XOR ; Return the answer ; Driver Code | def XorSum ( A , B , N ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT ans = ans ^ ( A [ i ] + B [ j ] ) NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = [ 4 , 6 , 0 , 0 , 3 , 3 ] NEW_LINE B = [ 0 ,... |
Maximum non | Python3 program for the above approach ; Function to find maximum distinct character after removing K character ; Freq implemented as hash table to store frequency of each character ; Store frequency of each character ; Insert each frequency in v ; Sort the freq of character in non - decreasing order ; Tr... | from collections import defaultdict NEW_LINE def maxDistinctChar ( s , n , k ) : NEW_LINE INDENT freq = defaultdict ( int ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT freq [ s [ i ] ] += 1 NEW_LINE DEDENT v = [ ] NEW_LINE for it in freq . values ( ) : NEW_LINE INDENT v . append ( it ) NEW_LINE DEDENT v . sort ( ) ... |
Split N as the sum of K numbers satisfying the given conditions | list to store prime numbers ; Function to generate prime numbers using SieveOfEratosthenes ; Boolean array to store primes ; If p is a prime ; Mark all its multiples as non - prime ; Print all prime numbers ; Function to generate n as the sum of k number... | primes = [ ] NEW_LINE def SieveOfEratosthenes ( ) : NEW_LINE INDENT prime = [ True ] * 10005 NEW_LINE p = 2 NEW_LINE while p * p <= 1000 : NEW_LINE INDENT if ( prime [ p ] == True ) : NEW_LINE INDENT for i in range ( p * p , 1001 , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT p += 1 NEW_LINE DEDENT ... |
Maximum modified Array sum possible by choosing elements as per the given conditions | Function that finds the maximum sum of the array elements according to the given condition ; Sort the array ; Take the max value from the array ; Iterate from the end of the array ; Check for the number had come before or not ; Take ... | def findMaxValue ( arr , n ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE ans = arr [ n - 1 ] NEW_LINE maxPossible = arr [ n - 1 ] NEW_LINE for i in range ( n - 2 , - 1 , - 1 ) : NEW_LINE INDENT if ( maxPossible > 0 ) : NEW_LINE INDENT if ( arr [ i ] >= maxPossible ) : NEW_LINE INDENT ans += ( maxPossible - 1 ) NEW_LINE m... |
Minimum cost to sort an Array such that swapping X and Y costs XY | Function returns the minimum cost to sort the given array ; Create array of pairs in which 1 st element is the array element and 2 nd element is index of first ; Initialize the total cost ; Sort the array with respect to array value ; Initialize the ov... | def minCost ( arr , n ) : NEW_LINE INDENT sortedarr = [ ] NEW_LINE total_cost = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT sortedarr . append ( [ arr [ i ] , i ] ) NEW_LINE DEDENT sortedarr . sort ( ) NEW_LINE overall_minimum = sortedarr [ 0 ] [ 0 ] NEW_LINE vis = [ False ] * n NEW_LINE for i in range ( n ) : NE... |
Maximize the last Array element as per the given conditions | Function to find the maximum possible value that can be placed at the last index ; Sort the array elements in ascending order ; If the first element is is not equal to 1 ; Traverse the array to make difference between adjacent elements <= 1 ; Driver Code | def maximizeFinalElement ( arr , n ) : NEW_LINE INDENT arr . sort ( ) ; NEW_LINE if ( arr [ 0 ] != 1 ) : NEW_LINE INDENT arr [ 0 ] = 1 ; NEW_LINE DEDENT for i in range ( 1 , n ) : NEW_LINE INDENT if ( arr [ i ] - arr [ i - 1 ] > 1 ) : NEW_LINE INDENT arr [ i ] = arr [ i - 1 ] + 1 ; NEW_LINE DEDENT DEDENT return arr [ n... |
Find the point on X | Function to find median of the array ; Sort the given array ; If number of elements are even ; Return the first median ; Otherwise ; Driver Code | def findLeastDist ( A , N ) : NEW_LINE INDENT A . sort ( ) ; NEW_LINE if ( N % 2 == 0 ) : NEW_LINE INDENT return A [ ( N - 1 ) // 2 ] ; NEW_LINE DEDENT else : NEW_LINE INDENT return A [ N // 2 ] ; NEW_LINE DEDENT DEDENT A = [ 4 , 1 , 5 , 10 , 2 ] ; NEW_LINE N = len ( A ) ; NEW_LINE print ( " ( " , findLeastDist ( A , N... |
Maximum sum of any submatrix of a Matrix which is sorted row | Function that finds the maximum Sub - Matrix Sum ; Number of rows in the matrix ; Number of columns in the matrix ; dp [ ] [ ] matrix to store the results of each iteration ; Base Case - The largest element in the matrix ; To stores the final result ; Find ... | def maxSubMatSum ( mat ) : NEW_LINE INDENT n = len ( mat ) NEW_LINE m = len ( mat [ 0 ] ) NEW_LINE dp = [ [ 0 ] * m for _ in range ( n ) ] NEW_LINE dp [ n - 1 ] [ m - 1 ] = mat [ n - 1 ] [ m - 1 ] NEW_LINE res = dp [ n - 1 ] [ m - 1 ] NEW_LINE for i in range ( m - 2 , - 1 , - 1 ) : NEW_LINE INDENT dp [ n - 1 ] [ i ] = ... |
Arrange the numbers in the Array as per given inequalities | Function to place the integers in between the inequality signs ; Sort the integers array and set the index of smallest and largest element ; Iterate over the inequalities ; Append the necessary integers per symbol ; Add the final integer ; Return the answer ;... | def formAnInequality ( integers , inequalities ) : NEW_LINE INDENT integers . sort ( ) NEW_LINE lowerIndex = 0 NEW_LINE higherIndex = len ( integers ) - 1 NEW_LINE sb = " " NEW_LINE for ch in inequalities : NEW_LINE INDENT if ( ch == ' < ' ) : NEW_LINE INDENT sb += ( " β " + chr ( integers [ lowerIndex ] ) + " β " + ch... |
Check if two arrays can be made equal by reversing subarrays multiple times | Function to check if array B can be made equal to array A ; Sort both the arrays ; Check if both the arrays are equal or not ; Driver Code | def canMadeEqual ( A , B , n ) : NEW_LINE INDENT A . sort ( ) NEW_LINE B . sort ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( A [ i ] != B [ i ] ) : NEW_LINE return False NEW_LINE DEDENT return True NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = [ 1 , 2 , 3 ] NEW_LINE B = [ 1 , 3 , 2 ]... |
Minimize difference between maximum and minimum of Array by at most K replacements | Function to find minimum difference between the maximum and the minimum elements arr [ ] by at most K replacements ; Check if turns are more than or equal to n - 1 then simply return zero ; Sort the array ; Set difference as the maximu... | def maxMinDifference ( arr , n , k ) : NEW_LINE INDENT if ( k >= n - 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT arr . sort ( ) NEW_LINE ans = arr [ n - 1 ] - arr [ 0 ] NEW_LINE i = k NEW_LINE j = n - 1 NEW_LINE while i >= 0 : NEW_LINE INDENT ans = min ( arr [ j ] - arr [ i ] , ans ) NEW_LINE i -= 1 NEW_LINE j -= 1 ... |
Check if a decreasing Array can be sorted using Triple cyclic shift | Python3 program for the above approach ; if array is 3 2 1 can ' t β β be β sorted β because β 2 β is β in β β its β correct β position , β 1 β β and β 3 β can ' t shift right because cyclic right shift takes place between 3 elements ; check if its p... | def sortarray ( arr , N ) : NEW_LINE INDENT if ( N == 3 ) : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT elif ( N % 4 == 0 or N % 4 == 1 ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE print ( N // 2 ) NEW_LINE k = 1 NEW_LINE for l in range ( N // 4 ) : NEW_LINE INDENT print ( k , k + 1 , N ) NEW_LINE print ( k + 1 ... |
Find least non | Python3 program to find the least non - overlapping number from a given set intervals ; Function to find the smallest non - overlapping number ; Create a visited array ; Find the first missing value ; Driver code | MAX = int ( 1e5 + 5 ) NEW_LINE def find_missing ( interval ) : NEW_LINE INDENT vis = [ 0 ] * ( MAX ) NEW_LINE for i in range ( len ( interval ) ) : NEW_LINE INDENT start = interval [ i ] [ 0 ] NEW_LINE end = interval [ i ] [ 1 ] NEW_LINE vis [ start ] += 1 NEW_LINE vis [ end + 1 ] -= 1 NEW_LINE DEDENT for i in range ( ... |
Find least non | function to find the smallest non - overlapping number ; Sort the intervals based on their starting value ; Check if any missing value exist ; Finally print the missing value ; Driver code | def find_missing ( interval ) : NEW_LINE INDENT interval . sort ( ) NEW_LINE mx = 0 NEW_LINE for i in range ( len ( interval ) ) : NEW_LINE INDENT if ( interval [ i ] [ 0 ] > mx ) : NEW_LINE INDENT print ( mx ) NEW_LINE return NEW_LINE DEDENT else : NEW_LINE INDENT mx = max ( mx , interval [ i ] [ 1 ] + 1 ) NEW_LINE DE... |
Maximum bitwise OR value of subsequence of length K | Function to convert bit array to decimal number ; Return the final result ; Function to find the maximum Bitwise OR value of subsequence of length K ; Initialize bit array of size 32 with all value as 0 ; Iterate for each index of bit [ ] array from 31 to 0 , and ch... | def build_num ( bit ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( 0 , 32 ) : NEW_LINE INDENT if ( bit [ i ] ) : NEW_LINE INDENT ans += ( 1 << i ) NEW_LINE DEDENT DEDENT return ans ; NEW_LINE DEDENT def maximumOR ( arr , n , k ) : NEW_LINE INDENT bit = [ 0 ] * 32 NEW_LINE for i in range ( 31 , - 1 , - 1 ) : NEW_... |
Lexicographically smallest string after M operations | Function to find the lexicographical smallest string after performing M operations ; Size of the given string ; Declare an array a ; For each i , a [ i ] contain number of operations to update s [ i ] to 'a ; Check if m >= ar [ i ] , then update s [ i ] to ' a ' de... | def smallest_string ( s , m ) : NEW_LINE INDENT n = len ( s ) ; NEW_LINE l = list ( s ) NEW_LINE a = [ 0 ] * n ; NEW_LINE DEDENT ' NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT distance = ord ( s [ i ] ) - ord ( ' a ' ) ; NEW_LINE if ( distance == 0 ) : NEW_LINE INDENT a [ i ] = 0 ; NEW_LINE DEDENT else : NEW_... |
Maximize jobs that can be completed under given constraint | Function to find maxiumum number of jobs ; Min Heap ; Sort ranges by start day ; Stores the minimum and maximum day in the ranges ; Iterating from min_day to max_day ; Insert the end day of the jobs which can be completed on i - th day in a priority queue ; P... | def find_maximum_jobs ( N , ranges ) : NEW_LINE INDENT queue = [ ] NEW_LINE ranges . sort ( ) NEW_LINE min_day = ranges [ 0 ] [ 0 ] NEW_LINE max_day = 0 NEW_LINE for i in range ( N ) : NEW_LINE max_day = max ( max_day , ranges [ i ] [ 1 ] ) NEW_LINE index , count_jobs = 0 , 0 NEW_LINE for i in range ( min_day , max_day... |
Minimize number of boxes by putting small box inside bigger one | Function to minimize the count ; Initial number of box ; Sort array of box size in increasing order ; Check is current box size is smaller than next box size ; Decrement box count Increment current box count Increment next box count ; Check if both box h... | def minBox ( arr , n ) : NEW_LINE INDENT box = n NEW_LINE arr . sort ( ) NEW_LINE curr_box , next_box = 0 , 1 NEW_LINE while ( curr_box < n and next_box < n ) : NEW_LINE INDENT if ( arr [ curr_box ] < arr [ next_box ] ) : NEW_LINE INDENT box = box - 1 NEW_LINE curr_box = curr_box + 1 NEW_LINE next_box = next_box + 1 NE... |
Sort a string lexicographically using triple cyclic shifts | Python3 program for sorting a string using cyclic shift of three indices ; Store the indices which haven 't attained its correct position ; Store the indices undergoing cyclic shifts ; If the element is not at it 's correct position ; Check if all 3 indices ... | import math NEW_LINE def sortString ( arr , n , moves ) : NEW_LINE INDENT pos = [ ] NEW_LINE indices = [ ] NEW_LINE flag = False NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] != i ) : NEW_LINE INDENT if ( arr [ arr [ arr [ i ] ] ] == i and arr [ arr [ i ] ] != i ) : NEW_LINE INDENT temp = arr [ arr [ i... |
Count of minimum reductions required to get the required sum K | Python3 program to find the count of minimum reductions required to get the required sum K ; Function to return the count of minimum reductions ; If the sum is already less than K ; Sort in non - increasing order of difference ; Driver Code ; Function Cal... | from typing import Any , List NEW_LINE def countReductions ( v : List [ Any ] , K : int ) -> int : NEW_LINE INDENT sum = 0 NEW_LINE for i in v : NEW_LINE INDENT sum += i [ 0 ] NEW_LINE DEDENT if ( sum <= K ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT v . sort ( key = lambda a : a [ 0 ] - a [ 1 ] ) NEW_LINE i = 0 NEW_LI... |
Merge two unsorted linked lists to get a sorted list | Create structure for a node ; Function to print the linked list ; Store the head of the linked list into a temporary node * and iterate ; Function takes the head of the LinkedList and the data as argument and if no LinkedList exists , it creates one with the head p... | class node : NEW_LINE INDENT def __init__ ( self , x ) : NEW_LINE INDENT self . data = x NEW_LINE self . next = None NEW_LINE DEDENT DEDENT def setData ( head ) : NEW_LINE INDENT tmp = head NEW_LINE while ( tmp != None ) : NEW_LINE INDENT print ( tmp . data , end = " β - > β " ) NEW_LINE tmp = tmp . next NEW_LINE DEDEN... |
Find K elements whose absolute difference with median of array is maximum | Function for calculating median ; Check for even case ; Function to find the K maximum absolute difference with the median of the array ; Sort the array ; Store median ; Find and store difference ; If diff [ i ] is greater print it . Else print... | def findMedian ( a , n ) : NEW_LINE INDENT if ( n % 2 != 0 ) : NEW_LINE INDENT return a [ int ( n / 2 ) ] NEW_LINE DEDENT return ( a [ int ( ( n - 1 ) / 2 ) ] + a [ int ( n / 2 ) ] ) / 2.0 NEW_LINE DEDENT def kStrongest ( arr , n , k ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE median = findMedian ( arr , n ) NEW_LINE d... |
Sort an array by swapping elements of different type specified by another array | Function to check if it is possible to sort the array in non - decreasing order by swapping elements of different types ; Consider the array to be already sorted ; Checking if array is already sorted ; Check for a pair which is in decreas... | def sorting_possible ( a , b , n ) : NEW_LINE INDENT sorted = True NEW_LINE type1 = 0 NEW_LINE type0 = 0 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if ( a [ i ] < a [ i - 1 ] ) : NEW_LINE INDENT sorted = False NEW_LINE break NEW_LINE DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT if ( b [ i ] == 0 ) : NE... |
Shortest path in a directed graph by DijkstraΓ’ β¬β’ s algorithm | Python3 implementation to find the shortest path in a directed graph from source vertex to the destination vertex ; Class of the node ; Adjacency list that shows the vertexNumber of child vertex and the weight of the edge ; Function to add the child for th... | class Pair : NEW_LINE INDENT def __init__ ( self , first , second ) : NEW_LINE INDENT self . first = first NEW_LINE self . second = second NEW_LINE DEDENT DEDENT infi = 1000000000 ; NEW_LINE class Node : NEW_LINE INDENT def __init__ ( self , vertexNumber ) : NEW_LINE INDENT self . vertexNumber = vertexNumber NEW_LINE s... |
Sort permutation of N natural numbers using triple cyclic right swaps | Function to sort the permutation with the given operations ; Visited array to check the array element is at correct position or not ; Loop to iterate over the elements of the given array ; Condition to check if the elements is at its correct positi... | def sortPermutation ( arr , n ) : NEW_LINE INDENT ans = [ ] NEW_LINE p = [ ] NEW_LINE visited = [ 0 ] * 200005 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( arr [ i ] == i ) : NEW_LINE INDENT visited [ i ] = 1 NEW_LINE continue NEW_LINE DEDENT else : NEW_LINE INDENT if ( visited [ i ] == False ) : NEW_LI... |
Maximize array sum by X increments when each element is divided by 10 | Python3 program for the above problem ; Initialize variables ; Add the current contribution of the element to the answer ; If the value is already maximum then we can 't change it ; Moves required to move to the next multiple of 10 ; No of times w... | def maximizeval10 ( a , n , k ) : NEW_LINE INDENT increments = 0 NEW_LINE ans = 0 NEW_LINE v = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT ans += ( a [ i ] // 10 ) NEW_LINE if ( a [ i ] == 1000 ) : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT v . append ( 10 - a [ i ] % 10 ) NEW_LINE incremen... |
Split array into two subarrays such that difference of their maximum is minimum | Python3 Program to split a given array such that the difference between their maximums is minimized . ; Sort the array ; Return the difference between two highest elements ; Driver Program | def findMinDif ( arr , N ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE return ( arr [ N - 1 ] - arr [ N - 2 ] ) NEW_LINE DEDENT arr = [ 7 , 9 , 5 , 10 ] NEW_LINE N = len ( arr ) NEW_LINE print ( findMinDif ( arr , N ) ) NEW_LINE |
Count of available non | Function to find the pivot index ; Function to implement Quick Sort ; Pivot is pointing to pivot index before which every element is smaller and after pivot , every element is greater ; Sort the array before pivot element ; Sort the array after pivot element ; Function to count the available in... | def partition ( arr , l , h ) : NEW_LINE INDENT pivot = arr [ l ] NEW_LINE i = l + 1 NEW_LINE j = h NEW_LINE while ( i <= j ) : NEW_LINE INDENT while ( i <= h and arr [ i ] < pivot ) : NEW_LINE INDENT i += 1 NEW_LINE DEDENT while ( j > l and arr [ j ] > pivot ) : NEW_LINE INDENT j -= 1 NEW_LINE DEDENT if ( i < j ) : NE... |
Maximum items that can be bought from the cost Array based on given conditions | Function to find the maximum number of items that can be bought from the given cost array ; Sort the given array ; Variables to store the prefix sum , answer and the counter variables ; Initializing the first element of the prefix array ; ... | def number ( a , n , p , k ) : NEW_LINE INDENT a . sort ( ) NEW_LINE pre = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT pre . append ( 0 ) NEW_LINE DEDENT ans = 0 NEW_LINE val = 0 NEW_LINE i = 0 NEW_LINE j = 0 NEW_LINE pre [ 0 ] = a [ 0 ] NEW_LINE if pre [ 0 ] <= p : NEW_LINE INDENT ans = 1 NEW_LINE DEDENT for i... |
Find the Maximum possible Sum for the given conditions | Function to find the maximum possible sum for the given conditions ; Sorting the array ; Variable to store the answer ; Iterating through the array ; If the value is greater than 0 ; If the value becomes 0 then break the loop because all the weights after this in... | def maxProfit ( arr ) : NEW_LINE INDENT arr . sort ( reverse = True ) NEW_LINE ans = 0 NEW_LINE for i in range ( len ( arr ) ) : NEW_LINE INDENT if ( arr [ i ] - ( 1 * i ) ) > 0 : NEW_LINE INDENT ans += ( arr [ i ] - ( 1 * i ) ) NEW_LINE DEDENT if ( arr [ i ] - ( 1 * i ) ) == 0 : NEW_LINE INDENT break NEW_LINE DEDENT D... |
Check if the array can be sorted only if the elements on given positions can be swapped | Function to check if the array can be sorted only if the elements on the given positions can be swapped ; Creating an array for marking the positions ; Iterating through the array and mark the positions ; Iterating through the giv... | def check_vector ( A , n , p ) : NEW_LINE INDENT pos = [ 0 for i in range ( len ( A ) ) ] NEW_LINE for i in range ( len ( p ) ) : NEW_LINE INDENT pos [ p [ i ] - 1 ] = 1 NEW_LINE DEDENT flag = 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( pos [ i ] == 0 ) : NEW_LINE INDENT continue NEW_LINE DEDENT j = i NEW_LI... |
Sort an array of strings based on the given order | Python3 program to sort an array of strings based on the given order ; For storing priority of each character ; Custom comparator function for sort ; Loop through the minimum size between two words ; Check if the characters at position i are different , then the word ... | from functools import cmp_to_key NEW_LINE mp = { } NEW_LINE def comp ( a , b ) : NEW_LINE INDENT for i in range ( min ( len ( a ) , len ( b ) ) ) : NEW_LINE INDENT if ( mp [ a [ i ] ] != mp [ b [ i ] ] ) : NEW_LINE INDENT if mp [ a [ i ] ] < mp [ b [ i ] ] : NEW_LINE INDENT return - 1 NEW_LINE DEDENT else : NEW_LINE IN... |
Sort elements of an array in increasing order of absolute difference of adjacent elements | Function to sort the elements of the array by difference ; Sorting the array ; Array to store the elements of the array ; Iterating over the length of the array to include each middle element of array ; Appending the middle elem... | def sortDiff ( arr , n ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE out = [ ] NEW_LINE while n : NEW_LINE INDENT out . append ( arr . pop ( n // 2 ) ) NEW_LINE n = n - 1 NEW_LINE DEDENT print ( * out ) NEW_LINE return out NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 8 , 1 , 2 , 3 , 0 ] NEW_L... |
Minimum cost of choosing the array element | Function that find the minimum cost of selecting array element ; Sorting the given array in increasing order ; To store the prefix sum of arr [ ] ; Update the pref [ ] to find the cost selecting array element by selecting at most M element ; Print the pref [ ] for the result... | def minimumCost ( arr , N , M ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE pref = [ ] NEW_LINE pref . append ( arr [ 0 ] ) NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT pref . append ( arr [ i ] + pref [ i - 1 ] ) NEW_LINE DEDENT for i in range ( M , N ) : NEW_LINE INDENT pref [ i ] += pref [ i - M ] NEW_LINE DEDE... |
Sort an Array alphabetically when each number is converted into words | Variable to store the word form of units digit and up to twenty ; Variable to store the word form of tens digit ; Function to convert a two digit number to the word by using the above defined arrays ; If n is more than 19 , divide it ; If n is non ... | one = [ " " , " one β " , " two β " , " three β " , " four β " , " five β " , " six β " , " seven β " , " eight β " , " nine β " , " ten β " , " eleven β " , " twelve β " , " thirteen β " , " fourteen β " , " fifteen β " , " sixteen β " , " seventeen β " , " eighteen β " , " nineteen β " ] NEW_LINE ten = [ " " , " " , ... |
Maximum Possible Rating of a Coding Contest | Python3 program to find the Maximum Possible Rating of a Coding Contest ; Function to sort all problems descending to upvotes ; Function to return maximum rating ; Declaring vector of pairs ; Each pair represents a problem with its points and upvotes ; Step ( 1 ) - Sort pro... | import heapq NEW_LINE def Comparator ( p1 ) : NEW_LINE INDENT return p1 [ 1 ] NEW_LINE DEDENT def FindMaxRating ( N , Point , Upvote , K ) : NEW_LINE INDENT vec = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT vec . append ( [ Point [ i ] , Upvote [ i ] ] ) NEW_LINE DEDENT vec . sort ( reverse = True , key = Compa... |
Find sum of all unique elements in the array for K queries | Function to find the sum of unique elements after Q Query ; Updating the array after processing each query ; Making it to 0 - indexing ; Iterating over the array to get the final array ; Variable to store the sum ; Hash to maintain perviously occured elements... | def uniqueSum ( A , R , N , M ) : NEW_LINE INDENT for i in range ( 0 , M ) : NEW_LINE INDENT l = R [ i ] [ 0 ] NEW_LINE r = R [ i ] [ 1 ] + 1 NEW_LINE l -= 1 NEW_LINE r -= 1 NEW_LINE A [ l ] += 1 NEW_LINE if ( r < N ) : NEW_LINE INDENT A [ r ] -= 1 NEW_LINE DEDENT DEDENT for i in range ( 1 , N ) : NEW_LINE INDENT A [ i... |
Find the Kth pair in ordered list of all possible sorted pairs of the Array | Function to find the k - th pair ; Sorting the array ; Iterating through the array ; Finding the number of same elements ; Checking if N * T is less than the remaining K . If it is , then arr [ i ] is the first element in the required pair ; ... | def kthpair ( n , k , arr ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE k -= 1 NEW_LINE i = 0 NEW_LINE while ( i < n ) : NEW_LINE INDENT t = 1 NEW_LINE while ( arr [ i ] == arr [ i + t ] ) : NEW_LINE INDENT t += 1 NEW_LINE DEDENT if ( t * n > k ) : NEW_LINE INDENT break NEW_LINE DEDENT k = k - t * n NEW_LINE i += t NEW_L... |
Minimum characters to be replaced to make frequency of all characters same | Function to find the minimum operations to convert given string to another with equal frequencies of characters ; Frequency of characters ; Loop to find the Frequency of each character ; Sort in decreasing order based on frequency ; Maximum po... | def minOperations ( s ) : NEW_LINE INDENT freq = [ 0 ] * 26 NEW_LINE n = len ( s ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT freq [ ord ( s [ i ] ) - ord ( ' A ' ) ] += 1 NEW_LINE DEDENT freq . sort ( reverse = True ) NEW_LINE answer = n NEW_LINE for i in range ( 1 , 27 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW... |
Check if it is possible to sort an array with conditional swapping of elements at distance K | Function for finding if it possible to obtain sorted array or not ; Iterate over all elements until K ; Store elements as multiples of K ; Sort the elements ; Put elements in their required position ; Check if the array becom... | def fun ( arr , n , k ) : NEW_LINE INDENT v = [ ] NEW_LINE for i in range ( k ) : NEW_LINE INDENT for j in range ( i , n , k ) : NEW_LINE INDENT v . append ( arr [ j ] ) ; NEW_LINE DEDENT v . sort ( ) ; NEW_LINE x = 0 NEW_LINE for j in range ( i , n , k ) : NEW_LINE INDENT arr [ j ] = v [ x ] ; NEW_LINE x += 1 NEW_LINE... |
Sort an Array based on the absolute difference of adjacent elements | Function that arrange the array such that all absolute difference between adjacent element are sorted ; To store the resultant array ; Sorting the given array in ascending order ; Variable to represent left and right ends of the given array ; Travers... | def sortedAdjacentDifferences ( arr , n ) : NEW_LINE INDENT ans = [ 0 ] * n NEW_LINE arr = sorted ( arr ) NEW_LINE l = 0 NEW_LINE r = n - 1 NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( i % 2 ) : NEW_LINE INDENT ans [ i ] = arr [ l ] NEW_LINE l += 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans [ i ... |
Minimum steps to convert an Array into permutation of numbers from 1 to N | Function to find minimum number of steps to convert a given sequence into a permutation ; Sort the given array ; To store the required minimum number of operations ; Find the operations on each step ; Return the answer ; Driver code ; Function ... | def get_permutation ( arr , n ) : NEW_LINE INDENT arr = sorted ( arr ) NEW_LINE result = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT result += abs ( arr [ i ] - ( i + 1 ) ) NEW_LINE DEDENT return result NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 0 , 2 , 3 , 4 , 1 , 6 , 8 , 9 ] NEW_L... |
Minimum increment or decrement required to sort the array | Top | Python3 program of the above approach ; Dp array to memoized the value recursive call ; Function to find the minimum increment or decrement needed to make the array sorted ; If only one element is present , then arr [ ] is sorted ; If dp [ N ] [ maxE ] i... | import sys NEW_LINE dp = [ [ 0 for x in range ( 1000 ) ] for y in range ( 1000 ) ] NEW_LINE def minimumIncDec ( arr , N , maxE , minE ) : NEW_LINE INDENT if ( N == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( dp [ N ] [ maxE ] ) : NEW_LINE INDENT return dp [ N ] [ maxE ] NEW_LINE DEDENT ans = sys . maxsize NEW_L... |
Sort the major diagonal of the matrix | Function to sort the major diagonal of the matrix ; Loop to find the ith minimum element from the major diagonal ; Loop to find the minimum element from the unsorted matrix ; Swap to put the minimum element at the beginning of the major diagonal of matrix ; Loop to print the matr... | def sortDiagonal ( a , M , N ) : NEW_LINE INDENT for i in range ( M ) : NEW_LINE INDENT sm = a [ i ] [ i ] NEW_LINE pos = i NEW_LINE for j in range ( i + 1 , N ) : NEW_LINE INDENT if ( sm > a [ j ] [ j ] ) : NEW_LINE INDENT sm = a [ j ] [ j ] NEW_LINE pos = j NEW_LINE DEDENT DEDENT a [ i ] [ i ] , a [ pos ] [ pos ] = a... |
Minimum cost to make an Array a permutation of first N natural numbers | Function to calculate minimum cost for making permutation of size N ; sorting the array in ascending order ; To store the required answer ; Traverse the whole array ; Return the required answer ; Driver code ; Function call | def make_permutation ( arr , n ) : NEW_LINE INDENT arr . sort ( ) ; NEW_LINE ans = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT ans += abs ( i + 1 - arr [ i ] ) ; NEW_LINE DEDENT return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 5 , 3 , 8 , 1 , 1 ] ; NEW_LINE n = len ( arr ) ... |
Find maximum sum from top to bottom row with no adjacent diagonal elements | Function to find the maximum path sum from top to bottom row ; Create an auxiliary array of next row with the element and it 's position ; Sort the auxiliary array ; Find maximum from row above to be added to the current element ; Find the max... | def maxSum ( V , n , m ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( n - 2 , - 1 , - 1 ) : NEW_LINE INDENT aux = [ ] NEW_LINE for j in range ( m ) : NEW_LINE INDENT aux . append ( [ V [ i + 1 ] [ j ] , j ] ) NEW_LINE DEDENT aux = sorted ( aux ) NEW_LINE aux = aux [ : : - 1 ] NEW_LINE for j in range ( m ) : NEW_... |
Count numbers whose maximum sum of distinct digit | Function to find the digit - sum of a number ; Loop to iterate the number digit - wise to find digit - sum ; variable to store last digit ; Function to find the count of number ; Vector to store the Sum of Digits ; Sum of digits for each element in vector ; Sorting th... | def SumofDigits ( digit ) : NEW_LINE INDENT sum = 0 NEW_LINE while ( digit != 0 ) : NEW_LINE INDENT rem = digit % 10 NEW_LINE sum += rem NEW_LINE digit //= 10 NEW_LINE DEDENT return sum NEW_LINE DEDENT def findCountofNumbers ( arr , n , M ) : NEW_LINE INDENT SumDigits = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDE... |
Minimum sum of product of elements of pairs of the given array | Function to find the minimum product ; Sort the array using STL sort ( ) function ; Initialise product to 1 ; Find product of sum of all pairs ; Return the product ; Driver code ; Function call to find product | def minimumProduct ( arr , n ) : NEW_LINE INDENT arr = sorted ( arr ) NEW_LINE product = 1 NEW_LINE for i in range ( 0 , n , 2 ) : NEW_LINE INDENT product *= ( arr [ i ] + arr [ i + 1 ] ) NEW_LINE DEDENT return product NEW_LINE DEDENT arr = [ 1 , 6 , 3 , 1 , 7 , 8 ] NEW_LINE n = len ( arr ) NEW_LINE print ( minimumProd... |
Minimum removals required to make ranges non | ; Sort by minimum starting point ; If the current starting point is less than the previous interval 's ending point (ie. there is an overlap) ; Increase rem ; Remove the interval with the higher ending point ; Driver Code | def minRemovels ( ranges ) : NEW_LINE INDENT size = len ( ranges ) NEW_LINE rem = 0 NEW_LINE ranges . sort ( ) NEW_LINE end = ranges [ 0 ] [ 1 ] NEW_LINE for i in range ( 1 , size ) : NEW_LINE INDENT if ( ranges [ i ] [ 0 ] < end ) : NEW_LINE INDENT rem += 1 NEW_LINE end = min ( ranges [ i ] [ 1 ] , end ) NEW_LINE DEDE... |
Check if elements of array can be arranged in AP , GP or HP | Returns true if arr [ 0. . n - 1 ] can form AP ; Base Case ; Sort array ; After sorting , difference between consecutive elements must be same . ; Traverse the given array and check if the difference between ith element and ( i - 1 ) th element is same or no... | def checkIsAP ( arr , n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return True NEW_LINE DEDENT arr . sort ( ) ; NEW_LINE d = arr [ 1 ] - arr [ 0 ] NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT if ( arr [ i ] - arr [ i - 1 ] != d ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE... |
Sort the Array by reversing the numbers in it | Function to return the reverse of n ; Function to sort the array according to the reverse of elements ; Vector to store the reverse with respective elements ; Inserting reverse with elements in the vector pair ; Sort the vector , this will sort the pair according to the r... | def reversDigits ( num ) : NEW_LINE INDENT rev_num = 0 ; NEW_LINE while ( num > 0 ) : NEW_LINE INDENT rev_num = rev_num * 10 + num % 10 ; NEW_LINE num = num // 10 ; NEW_LINE DEDENT return rev_num ; NEW_LINE DEDENT def sortArr ( arr , n ) : NEW_LINE INDENT vp = [ ] ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT vp . ... |
Count number of pairs with positive sum in an array | Returns number of pairs in arr [ 0. . n - 1 ] with positive sum ; Sort the array in increasing order ; Intialise result ; Intialise first and second pointer ; Till the pointers doesn 't converge traverse array to count the pairs ; If sum of arr [ i ] && arr [ j... | def CountPairs ( arr , n ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE count = 0 ; NEW_LINE l = 0 ; r = n - 1 ; NEW_LINE while ( l < r ) : NEW_LINE INDENT if ( arr [ l ] + arr [ r ] > 0 ) : NEW_LINE INDENT count += ( r - l ) ; NEW_LINE r -= 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT l += 1 ; NEW_LINE DEDENT DEDENT return... |
Sort the given Matrix | Memory Efficient Approach | Function to sort the matrix ; Number of elements in matrix ; Loop to sort the matrix using Bubble Sort ; Condition to check if the Adjacent elements ; Swap if previous value is greater ; Loop to print the matrix ; Driver Code ; Function call to sort ; Function call to... | def sortMat ( data , row , col ) : NEW_LINE INDENT size = row * col NEW_LINE for i in range ( 0 , size ) : NEW_LINE INDENT for j in range ( 0 , size - 1 ) : NEW_LINE INDENT if ( data [ j // col ] [ j % col ] > data [ ( j + 1 ) // col ] [ ( j + 1 ) % col ] ) : NEW_LINE INDENT temp = data [ j // col ] [ j % col ] NEW_LIN... |
Partition the array into two odd length groups with minimized absolute difference between their median | Function to find minimise the median between partition array ; Sort the given array arr [ ] ; Return the difference of two middle element of the arr [ ] ; Driver Code ; Size of arr [ ] ; Function that returns the mi... | def minimiseMedian ( arr , n ) : NEW_LINE INDENT arr . sort ( ) ; NEW_LINE ans = abs ( arr [ n // 2 ] - arr [ ( n // 2 ) - 1 ] ) ; NEW_LINE return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 15 , 25 , 35 , 50 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( minimiseMedian ( arr , n ) ... |
Maximum number of overlapping Intervals | Function that prmaximum overlap among ranges ; variable to store the maximum count ; storing the x and y coordinates in data vector ; pushing the x coordinate ; pushing the y coordinate ; sorting of ranges ; Traverse the data vector to count number of overlaps ; if x occur it m... | def overlap ( v ) : NEW_LINE INDENT ans = 0 NEW_LINE count = 0 NEW_LINE data = [ ] NEW_LINE for i in range ( len ( v ) ) : NEW_LINE INDENT data . append ( [ v [ i ] [ 0 ] , ' x ' ] ) NEW_LINE data . append ( [ v [ i ] [ 1 ] , ' y ' ] ) NEW_LINE DEDENT data = sorted ( data ) NEW_LINE for i in range ( len ( data ) ) : NE... |
Making three numbers equal with the given operations | Function that returns true if a , b and c can be made equal with the given operations ; Sort the three numbers ; Find the sum of difference of the 3 rd and 2 nd element and the 3 rd and 1 st element ; Subtract the difference from k ; Check the required condition ; ... | def canBeEqual ( a , b , c , k ) : NEW_LINE INDENT arr = [ 0 ] * 3 ; NEW_LINE arr [ 0 ] = a ; NEW_LINE arr [ 1 ] = b ; NEW_LINE arr [ 2 ] = c ; NEW_LINE arr . sort ( ) NEW_LINE diff = 2 * arr [ 2 ] - arr [ 1 ] - arr [ 0 ] ; NEW_LINE k = k - diff ; NEW_LINE if ( k < 0 or k % 3 != 0 ) : NEW_LINE INDENT return False ; NEW... |
Arrange numbers to form a valid sequence | Function to organize the given numbers to form a valid sequence . ; Sorting the array ; Two pointer technique to organize the numbers ; Driver code | def orgazineInOrder ( vec , op , n ) : NEW_LINE INDENT result = [ 0 ] * n ; NEW_LINE vec . sort ( ) ; NEW_LINE i = 0 ; NEW_LINE j = n - 1 ; NEW_LINE k = 0 ; NEW_LINE while ( i <= j and k <= n - 2 ) : NEW_LINE INDENT if ( op [ k ] == ' < ' ) : NEW_LINE INDENT result [ k ] = vec [ i ] ; NEW_LINE i += 1 ; NEW_LINE DEDENT ... |
Find the distance between two person after reconstruction of queue | Function to find the correct order and then return the distance between the two persons ; Make pair of both height & infront and insert to vector ; Sort the vector in ascending order ; Find the correct place for every person ; Insert into position vec... | def getDistance ( arr , n , a , b ) : NEW_LINE INDENT vp = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT vp . append ( [ arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ] ) NEW_LINE DEDENT vp = sorted ( vp ) NEW_LINE pos = [ 0 for i in range ( n ) ] NEW_LINE for i in range ( len ( vp ) ) : NEW_LINE INDENT height = vp [ i ] [ 0... |
Minimize the sum of differences of consecutive elements after removing exactly K elements | function to find minimum sum ; variable to store final answer and initialising it with the values when 0 elements is removed from the left and K from the right . ; loop to simulate removal of elements ; removing i elements from ... | def findSum ( arr , n , k ) : NEW_LINE INDENT ans = arr [ n - k - 1 ] - arr [ 0 ] ; NEW_LINE for i in range ( 1 , k + 1 ) : NEW_LINE INDENT ans = min ( arr [ n - 1 - ( k - i ) ] - arr [ i ] , ans ) ; NEW_LINE DEDENT return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 2 , 100 , 120... |
Minimum elements to be removed from the ends to make the array sorted | Function to return the minimum number of elements to be removed from the ends of the array to make it sorted ; To store the final answer ; Two pointer loop ; While the array is increasing increment j ; Updating the ans ; Updating the left pointer ;... | def findMin ( arr , n ) : NEW_LINE INDENT ans = 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT j = i + 1 NEW_LINE while ( j < n and arr [ j ] >= arr [ j - 1 ] ) : NEW_LINE INDENT j += 1 NEW_LINE DEDENT ans = max ( ans , j - i ) NEW_LINE i = j - 1 NEW_LINE DEDENT return n - ans NEW_LINE DEDENT arr = [ 3 , 2 , 1 ] NEW... |
Number of subsequences of maximum length K containing no repeated elements | Returns number of subsequences of maximum length k and contains no repeated element ; Sort the array a [ ] ; Store the frequencies of all the distinct element in the vector arr ; count is the the number of such subsequences ; Create a 2 - d ar... | def countSubSeq ( a , n , k ) : NEW_LINE INDENT a . sort ( reverse = False ) NEW_LINE arr = [ ] NEW_LINE i = 0 NEW_LINE while ( i < n ) : NEW_LINE INDENT count = 1 NEW_LINE x = a [ i ] NEW_LINE i += 1 NEW_LINE while ( i < n and a [ i ] == x ) : NEW_LINE INDENT count += 1 NEW_LINE i += 1 NEW_LINE DEDENT arr . append ( c... |
Find the count of unvisited indices in an infinite array | Function to return the count of unvisited indices starting from the index 0 ; Largest index that cannot be visited ; Push the index to the queue ; To store the required count ; Current index that cannot be visited ; Increment the count for the current index ; (... | def countUnvisited ( n , m ) : NEW_LINE INDENT i = 0 NEW_LINE X = ( m * n ) - m - n NEW_LINE queue = [ ] NEW_LINE queue . append ( X ) NEW_LINE count = 0 NEW_LINE while ( len ( queue ) > 0 ) : NEW_LINE INDENT curr = queue [ 0 ] NEW_LINE queue . remove ( queue [ 0 ] ) NEW_LINE count += 1 NEW_LINE if ( curr - m > 0 ) : N... |
Check whether the string S1 can be made equal to S2 with the given operation | Function to return the string formed by the odd indexed characters of s ; Function to return the string formed by the even indexed characters of s ; Function that returns true if s1 can be made equal to s2 with the given operation ; Get the ... | def partOdd ( s ) : NEW_LINE INDENT odd = [ ] NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if i % 2 != 0 : NEW_LINE INDENT odd . append ( s [ i ] ) NEW_LINE DEDENT DEDENT return odd NEW_LINE DEDENT def partEven ( s ) : NEW_LINE INDENT even = [ ] NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if i % ... |
Sort the given stack elements based on their modulo with K | Function to sort the stack using another stack based on the values of elements modulo k ; Pop out the first element ; While temporary stack is not empty ; The top of the stack modulo k is greater than ( temp & k ) or if they are equal then compare the values ... | def sortStack ( input1 , k ) : NEW_LINE INDENT tmpStack = [ ] NEW_LINE while ( len ( input1 ) != 0 ) : NEW_LINE INDENT tmp = input1 [ - 1 ] NEW_LINE input1 . pop ( ) NEW_LINE while ( len ( tmpStack ) != 0 ) : NEW_LINE INDENT tmpStackMod = tmpStack [ - 1 ] % k NEW_LINE tmpMod = tmp % k NEW_LINE if ( ( tmpStackMod > tmpM... |
Longest sub | Function to return the length of the largest subsequence with non - negative sum ; To store the current sum ; Sort the input array in non - increasing order ; Traverse through the array ; Add the current element to the sum ; Condition when c_sum falls below zero ; Complete array has a non - negative sum ;... | def maxLen ( arr , n ) : NEW_LINE INDENT c_sum = 0 ; NEW_LINE arr . sort ( reverse = True ) ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT c_sum += arr [ i ] ; NEW_LINE if ( c_sum < 0 ) : NEW_LINE INDENT return i ; NEW_LINE DEDENT DEDENT return n ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT ar... |
Find Partition Line such that sum of values on left and right is equal | Python3 implementation of the approach ; Function that returns true if the required line exists ; To handle negative values from x [ ] ; Update arr [ ] such that arr [ i ] contains the sum of all v [ j ] such that x [ j ] = i for all valid values ... | MAX = 1000 ; NEW_LINE def lineExists ( x , y , v , n ) : NEW_LINE INDENT size = ( 2 * MAX ) + 1 ; NEW_LINE arr = [ 0 ] * size ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT arr [ x [ i ] + MAX ] += v [ i ] ; NEW_LINE DEDENT for i in range ( 1 , size ) : NEW_LINE INDENT arr [ i ] += arr [ i - 1 ] ; NEW_LINE DEDENT if... |
Maximum sum of minimums of pairs in an array | Function to return the maximum required sum of the pairs ; Sort the array ; To store the sum ; Start making pairs of every two consecutive elements as n is even ; Minimum element of the current pair ; Return the maximum possible sum ; Driver code | def maxSum ( a , n ) : NEW_LINE INDENT a . sort ( ) ; NEW_LINE sum = 0 ; NEW_LINE for i in range ( 0 , n - 1 , 2 ) : NEW_LINE INDENT sum += a [ i ] ; NEW_LINE DEDENT return sum ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 3 , 2 , 1 , 4 , 5 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print... |
Sort elements by modulo with K | Utility function to prthe contents of an array ; Function to sort the array elements based on their modulo with K ; Create K empty vectors ; Update the vectors such that v [ i ] will contain all the elements that give remainder as i when divided by k ; Sorting all the vectors separately... | def printArr ( arr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = ' β ' ) NEW_LINE DEDENT DEDENT def sortWithRemainder ( arr , n , k ) : NEW_LINE INDENT v = [ [ ] for i in range ( k ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT v [ arr [ i ] % k ] . append ( arr [ i ] ) N... |
Minimum increment operations to make K elements equal | Function to return the minimum number of increment operations required to make any k elements of the array equal ; Sort the array in increasing order ; Calculate the number of operations needed to make 1 st k elements equal to the kth element i . e . the 1 st wind... | def minOperations ( ar , k ) : NEW_LINE INDENT ar = sorted ( ar ) NEW_LINE opsNeeded = 0 NEW_LINE for i in range ( k ) : NEW_LINE INDENT opsNeeded += ar [ k - 1 ] - ar [ i ] NEW_LINE DEDENT ans = opsNeeded NEW_LINE for i in range ( k , len ( ar ) ) : NEW_LINE INDENT opsNeeded = opsNeeded - ( ar [ i - 1 ] - ar [ i - k ]... |
Lexicographical ordering using Heap Sort | Used for index in heap ; Predefining the heap array ; Defining formation of the heap ; Iterative heapiFy ; Just swapping if the element is smaller than already stored element ; Swapping the current index with its child ; Moving upward in the heap ; Defining heap sort ; Taking ... | x = - 1 ; NEW_LINE heap = [ 0 ] * 1000 ; NEW_LINE def heapForm ( k ) : NEW_LINE INDENT global x ; NEW_LINE x += 1 ; NEW_LINE heap [ x ] = k ; NEW_LINE child = x ; NEW_LINE index = x // 2 ; NEW_LINE while ( index >= 0 ) : NEW_LINE INDENT if ( heap [ index ] > heap [ child ] ) : NEW_LINE INDENT tmp = heap [ index ] ; NEW... |
Find Kth element in an array containing odd elements first and then even elements | Function to return the kth element in the modified array ; First odd number ; Insert the odd number ; Next odd number ; First even number ; Insert the even number ; Next even number ; Return the kth element ; Driver code | def getNumber ( n , k ) : NEW_LINE INDENT arr = [ 0 ] * n ; NEW_LINE i = 0 ; NEW_LINE odd = 1 ; NEW_LINE while ( odd <= n ) : NEW_LINE INDENT arr [ i ] = odd ; NEW_LINE i += 1 ; NEW_LINE odd += 2 ; NEW_LINE DEDENT even = 2 ; NEW_LINE while ( even <= n ) : NEW_LINE INDENT arr [ i ] = even ; NEW_LINE i += 1 ; NEW_LINE ev... |
Swap Alternate Boundary Pairs | Utility function to print the contents of an array ; Function to update the array ; Initialize the pointers ; While there are elements to swap ; Update the pointers ; Print the updated array ; Driver code | def printArr ( arr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = " β " ) ; NEW_LINE DEDENT DEDENT def UpdateArr ( arr , n ) : NEW_LINE INDENT i = 0 ; NEW_LINE j = n - 1 ; NEW_LINE while ( i < j ) : NEW_LINE INDENT temp = arr [ i ] ; NEW_LINE arr [ i ] = arr [ j ] ; NEW_LINE ar... |
Count permutation such that sequence is non decreasing | Python3 implementation of the approach ; To store the factorials ; Function to update fact [ ] array such that fact [ i ] = i ! ; 0 ! = 1 ; i ! = i * ( i - 1 ) ! ; Function to return the count of possible permutations ; To store the result ; Sort the array ; Init... | N = 20 NEW_LINE fact = [ 0 ] * N ; NEW_LINE def pre ( ) : NEW_LINE INDENT fact [ 0 ] = 1 ; NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT fact [ i ] = i * fact [ i - 1 ] ; NEW_LINE DEDENT DEDENT def CountPermutation ( a , n ) : NEW_LINE INDENT ways = 1 ; NEW_LINE a . sort ( ) ; NEW_LINE size = 1 ; NEW_LINE for i i... |
Smallest element greater than X not present in the array | Function to return the smallest element greater than x which is not present in a [ ] ; Sort the array ; Continue until low is less than or equals to high ; Find mid ; If element at mid is less than or equals to searching element ; If mid is equals to searching ... | def Next_greater ( a , n , x ) : NEW_LINE INDENT a = sorted ( a ) NEW_LINE low , high , ans = 0 , n - 1 , x + 1 NEW_LINE while ( low <= high ) : NEW_LINE INDENT mid = ( low + high ) // 2 NEW_LINE if ( a [ mid ] <= ans ) : NEW_LINE INDENT if ( a [ mid ] == ans ) : NEW_LINE INDENT ans += 1 NEW_LINE high = n - 1 NEW_LINE ... |
Alternate XOR operations on sorted array | Python 3 implementation of the approach ; Function to find the maximum and the minimum elements from the array after performing the given operation k times ; To store the current sequence of elements ; To store the next sequence of elements after xoring with current elements ;... | MAX = 10000 NEW_LINE import sys NEW_LINE from math import ceil , floor NEW_LINE def xorOnSortedArray ( arr , n , k , x ) : NEW_LINE INDENT arr1 = [ 0 for i in range ( MAX + 1 ) ] NEW_LINE arr2 = [ 0 for i in range ( MAX + 1 ) ] NEW_LINE xor_val = [ 0 for i in range ( MAX + 1 ) ] NEW_LINE for i in range ( n ) : NEW_LINE... |
Arrange N elements in circular fashion such that all elements are strictly less than sum of adjacent elements | Function to print the arrangement that satisifes the given condition ; Sort the array initially ; Array that stores the arrangement ; Once the array is sorted Re - fill the array again in the mentioned way in... | def printArrangement ( a , n ) : NEW_LINE INDENT a = sorted ( a ) NEW_LINE b = [ 0 for i in range ( n ) ] NEW_LINE low = 0 NEW_LINE high = n - 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( i % 2 == 0 ) : NEW_LINE INDENT b [ low ] = a [ i ] NEW_LINE low += 1 NEW_LINE DEDENT else : NEW_LINE INDENT b [ high ] = a... |
Greatest contiguous sub | Function that returns the sub - array ; Data - structure to store all the sub - arrays of size K ; Iterate to find all the sub - arrays ; Store the sub - array elements in the array ; Push the vector in the container ; Sort the vector of elements ; The last sub - array in the sorted order will... | def findSubarray ( a , k , n ) : NEW_LINE INDENT vec = [ ] NEW_LINE for i in range ( n - k + 1 ) : NEW_LINE INDENT temp = [ ] NEW_LINE for j in range ( i , i + k ) : NEW_LINE INDENT temp . append ( a [ j ] ) NEW_LINE DEDENT vec . append ( temp ) NEW_LINE DEDENT vec = sorted ( vec ) NEW_LINE return vec [ len ( vec ) - 1... |
Unbounded Fractional Knapsack | Python implementation of the approach ; Function to return the maximum required value ; maxratio will store the maximum value to weight ratio we can have for any item and maxindex will store the index of that element ; Find the maximum ratio ; The item with the maximum value to weight ra... | import sys NEW_LINE def knapSack ( W , wt , val , n ) : NEW_LINE INDENT maxratio = - sys . maxsize - 1 ; NEW_LINE maxindex = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( ( val [ i ] / wt [ i ] ) > maxratio ) : NEW_LINE INDENT maxratio = ( val [ i ] / wt [ i ] ) ; NEW_LINE maxindex = i ; NEW_LINE DEDENT DEDE... |
Sort an array without changing position of negative numbers | Function to sort the array such that negative values do not get affected ; Store all non - negative values ; Sort non - negative values ; If current element is non - negative then update it such that all the non - negative values are sorted ; Print the sorte... | def sortArray ( a , n ) : NEW_LINE INDENT ans = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] >= 0 ) : NEW_LINE INDENT ans . append ( a [ i ] ) NEW_LINE DEDENT DEDENT ans = sorted ( ans ) NEW_LINE j = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] >= 0 ) : NEW_LINE INDENT a [ i ] = an... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.