text
stringlengths 1
636
| code
stringlengths 8
1.89k
|
---|---|
Update fourth minimum element | elif ( arr [ i ] < minD ) : NEW_LINE INDENT minD = arr [ i ] NEW_LINE DEDENT x = maxA * maxB * maxC * maxD NEW_LINE y = minA * minB * minC * minD NEW_LINE z = minA * minB * maxA * maxB NEW_LINE |
Return the maximum of x , y and z | return max ( x , max ( y , z ) ) NEW_LINE |
Driver program to test above function | if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , - 4 , 3 , - 6 , 7 , 0 ] NEW_LINE n = len ( arr ) NEW_LINE max1 = maxProduct ( arr , n ) NEW_LINE if ( max1 == - 1 ) : NEW_LINE INDENT print ( " No β Quadruple β Exists " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Maximum β product β is " , max1 ) NEW_LINE DEDENT DEDENT |
Returns the number of triplets with distance between farthest points <= L | def countTripletsLessThanL ( n , L , arr ) : NEW_LINE |
sort to get ordered triplets so that we can find the distance between farthest points belonging to a triplet | arr . sort ( ) NEW_LINE ways = 0 NEW_LINE |
generate and check for all possible triplets : { arr [ i ] , arr [ j ] , arr [ k ] } | for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT for k in range ( j + 1 , n ) : NEW_LINE DEDENT DEDENT |
Since the array is sorted the farthest points will be a [ i ] and a [ k ] ; | mostDistantDistance = arr [ k ] - arr [ i ] NEW_LINE if ( mostDistantDistance <= L ) : NEW_LINE INDENT ways += 1 NEW_LINE DEDENT return ways NEW_LINE |
Driver Code | if __name__ == " _ _ main _ _ " : NEW_LINE |
set of n points on the X axis | arr = [ 1 , 2 , 3 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE L = 3 NEW_LINE ans = countTripletsLessThanL ( n , L , arr ) NEW_LINE print ( " Total β Number β of β ways β = " , ans ) NEW_LINE |
Return the lower bound i . e smallest index of element having value greater or equal to value | def binary_lower ( value , arr , n ) : NEW_LINE INDENT start = 0 NEW_LINE end = n - 1 NEW_LINE ans = - 1 NEW_LINE while ( start <= end ) : NEW_LINE INDENT mid = ( start + end ) // 2 NEW_LINE if ( arr [ mid ] >= value ) : NEW_LINE INDENT end = mid - 1 NEW_LINE ans = mid NEW_LINE DEDENT else : NEW_LINE INDENT start = mid + 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT |
Return the number of triplet indices satisfies the three constraints | def countTriplet ( arr , n , k ) : NEW_LINE INDENT count = 0 NEW_LINE DEDENT |
sort the array | arr . sort ( ) NEW_LINE |
for each element from index 2 to n - 1. | for i in range ( 2 , n ) : NEW_LINE |
finding the lower bound of arr [ i ] - k . | cur = ( binary_lower ( arr [ i ] - k , arr , n ) ) NEW_LINE |
If there are at least two elements between lower bound and current element . | if ( cur <= i - 2 ) : NEW_LINE |
increment the count by lb - i C 2. | count += ( ( i - cur ) * ( i - cur - 1 ) ) // 2 NEW_LINE return count NEW_LINE |
Driver code | if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 1 , 2 , 2 , 3 ] NEW_LINE k = 1 NEW_LINE n = len ( arr ) NEW_LINE print ( countTriplet ( arr , n , k ) ) NEW_LINE DEDENT |
Python3 program to find minimum sum of roots of a given polynomial | import sys NEW_LINE def getMinimumSum ( arr , n ) : NEW_LINE |
resultant list | res = [ ] NEW_LINE |
a lis that store indices of the positive elements | pos = [ ] NEW_LINE |
a list that store indices of the negative elements | neg = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] > 0 ) : NEW_LINE INDENT pos . append ( i ) NEW_LINE DEDENT elif ( arr [ i ] < 0 ) : NEW_LINE INDENT neg . append ( i ) NEW_LINE DEDENT DEDENT |
Case - 1 : | if ( len ( pos ) >= 2 and len ( neg ) >= 2 ) : NEW_LINE INDENT posMax = - sys . maxsize - 1 NEW_LINE posMaxIdx = - 1 NEW_LINE posMin = sys . maxsize NEW_LINE posMinIdx = - 1 NEW_LINE negMax = - sys . maxsize - 1 NEW_LINE negMaxIdx = - 1 NEW_LINE negMin = sys . maxsize NEW_LINE negMinIdx = - 1 NEW_LINE for i in range ( len ( pos ) ) : NEW_LINE INDENT if ( arr [ pos [ i ] ] > posMax ) : NEW_LINE INDENT posMaxIdx = pos [ i ] NEW_LINE posMax = arr [ posMaxIdx ] NEW_LINE DEDENT DEDENT for i in range ( len ( pos ) ) : NEW_LINE INDENT if ( arr [ pos [ i ] ] < posMin and pos [ i ] != posMaxIdx ) : NEW_LINE INDENT posMinIdx = pos [ i ] NEW_LINE posMin = arr [ posMinIdx ] NEW_LINE DEDENT DEDENT for i in range ( len ( neg ) ) : NEW_LINE INDENT if ( abs ( arr [ neg [ i ] ] ) > negMax ) : NEW_LINE INDENT negMaxIdx = neg [ i ] NEW_LINE negMax = abs ( arr [ negMaxIdx ] ) NEW_LINE DEDENT DEDENT for i in range ( len ( neg ) ) : NEW_LINE INDENT if ( abs ( arr [ neg [ i ] ] ) < negMin and neg [ i ] != negMaxIdx ) : NEW_LINE INDENT negMinIdx = neg [ i ] NEW_LINE negMin = abs ( arr [ negMinIdx ] ) NEW_LINE DEDENT DEDENT posVal = ( - 1.0 * posMax / posMin ) NEW_LINE negVal = ( - 1.0 * negMax / negMin ) NEW_LINE if ( posVal < negVal ) : NEW_LINE INDENT res . append ( arr [ posMinIdx ] ) NEW_LINE res . append ( arr [ posMaxIdx ] ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( i != posMinIdx and i != posMaxIdx ) : NEW_LINE INDENT res . append ( arr [ i ] ) NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT res . append ( arr [ negMinIdx ] ) NEW_LINE res . append ( arr [ negMaxIdx ] ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( i != negMinIdx and i != negMaxIdx ) : NEW_LINE INDENT resal . append ( arr [ i ] ) NEW_LINE DEDENT DEDENT DEDENT for i in range ( len ( res ) ) : NEW_LINE INDENT print ( res [ i ] , end = " β " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT |
Case - 2 : | elif ( len ( pos ) >= 2 ) : NEW_LINE INDENT posMax = - sys . maxsize NEW_LINE posMaxIdx = - 1 NEW_LINE posMin = sys . maxsize NEW_LINE posMinIdx = - 1 NEW_LINE for i in range ( len ( pos ) ) : NEW_LINE INDENT if ( arr [ pos [ i ] ] > posMax ) : NEW_LINE INDENT posMaxIdx = pos [ i ] NEW_LINE posMax = arr [ posMaxIdx ] NEW_LINE DEDENT DEDENT for i in range ( len ( pos ) ) : NEW_LINE INDENT if ( arr [ pos [ i ] ] < posMin and pos [ i ] != posMaxIdx ) : NEW_LINE INDENT posMinIdx = pos [ i ] NEW_LINE posMin = arr [ posMinIdx ] NEW_LINE DEDENT DEDENT res . append ( arr [ posMinIdx ] ) NEW_LINE res . append ( arr [ posMaxIdx ] ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( i != posMinIdx and i != posMaxIdx ) : NEW_LINE INDENT res . append ( arr [ i ] ) NEW_LINE DEDENT DEDENT for i in range ( len ( res ) ) : NEW_LINE INDENT print ( res [ i ] , end = " β " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT |
Case - 3 : | elif ( len ( neg ) >= 2 ) : NEW_LINE INDENT negMax = - sys . maxsize NEW_LINE negMaxIdx = - 1 NEW_LINE negMin = sys . maxsize NEW_LINE negMinIdx = - 1 NEW_LINE for i in range ( len ( neg ) ) : NEW_LINE INDENT if ( abs ( arr [ neg [ i ] ] ) > negMax ) : NEW_LINE INDENT negMaxIdx = neg [ i ] NEW_LINE negMax = abs ( arr [ negMaxIdx ] ) NEW_LINE DEDENT DEDENT for i in range ( len ( neg ) ) : NEW_LINE INDENT if ( abs ( arr [ neg [ i ] ] ) < negMin and neg [ i ] != negMaxIdx ) : NEW_LINE INDENT negMinIdx = neg [ i ] NEW_LINE negMin = abs ( arr [ negMinIdx ] ) NEW_LINE DEDENT DEDENT res . append ( arr [ negMinIdx ] ) NEW_LINE res . append ( arr [ negMaxIdx ] ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( i != negMinIdx and i != negMaxIdx ) : NEW_LINE INDENT res . append ( arr [ i ] ) NEW_LINE DEDENT DEDENT for i in range ( len ( res ) ) : NEW_LINE INDENT print ( res [ i ] , end = " β " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT |
Case - 4 : | else : NEW_LINE INDENT print ( " No β swap β required " ) NEW_LINE DEDENT |
Driver code | if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ - 4 , 1 , 6 , - 3 , - 2 , - 1 ] NEW_LINE n = len ( arr ) NEW_LINE getMinimumSum ( arr , n ) NEW_LINE DEDENT |
Python3 code for Longest Palindromic substring using Palindromic Tree data structure | class Node : NEW_LINE INDENT def __init__ ( self , length = None , suffixEdge = None ) : NEW_LINE DEDENT |
store start and end indexes of current Node inclusively | self . start = None NEW_LINE self . end = None NEW_LINE |
Stores length of substring | self . length = length NEW_LINE |
stores insertion Node for all characters a - z | self . insertionEdge = [ 0 ] * 26 NEW_LINE |
stores the Maximum Palindromic Suffix Node for the current Node | self . suffixEdge = suffixEdge NEW_LINE |
Stores Node information for constant time access | tree = [ Node ( ) for i in range ( MAXN ) ] NEW_LINE |
Keeps track the Current Node while insertion | currNode , ptr = 1 , 2 NEW_LINE tree [ 1 ] = root1 NEW_LINE tree [ 2 ] = root2 NEW_LINE s = " forgeeksskeegfor " NEW_LINE for i in range ( 0 , len ( s ) ) : NEW_LINE INDENT insert ( i ) NEW_LINE DEDENT |
Function to insert edge in tree | def insert ( currIndex ) : NEW_LINE INDENT global currNode , ptr NEW_LINE DEDENT |
Finding X , such that s [ currIndex ] + X + s [ currIndex ] is palindrome . | temp = currNode NEW_LINE while True : NEW_LINE INDENT currLength = tree [ temp ] . length NEW_LINE if ( currIndex - currLength >= 1 and ( s [ currIndex ] == s [ currIndex - currLength - 1 ] ) ) : NEW_LINE INDENT break NEW_LINE DEDENT temp = tree [ temp ] . suffixEdge NEW_LINE DEDENT |
Check if s [ currIndex ] + X + s [ currIndex ] is already Present in tree . | if tree [ temp ] . insertionEdge [ ord ( s [ currIndex ] ) - ord ( ' a ' ) ] != 0 : NEW_LINE INDENT currNode = tree [ temp ] . insertionEdge [ ord ( s [ currIndex ] ) - ord ( ' a ' ) ] NEW_LINE return NEW_LINE DEDENT |
Else Create new node | ptr += 1 NEW_LINE tree [ temp ] . insertionEdge [ ord ( s [ currIndex ] ) - ord ( ' a ' ) ] = ptr NEW_LINE tree [ ptr ] . end = currIndex NEW_LINE tree [ ptr ] . length = tree [ temp ] . length + 2 NEW_LINE tree [ ptr ] . start = ( tree [ ptr ] . end - tree [ ptr ] . length + 1 ) NEW_LINE |
Setting suffix edge for newly Created Node . | currNode = ptr NEW_LINE temp = tree [ temp ] . suffixEdge NEW_LINE |
Longest Palindromic suffix for a string of length 1 is a Null string . | if tree [ currNode ] . length == 1 : NEW_LINE INDENT tree [ currNode ] . suffixEdge = 2 NEW_LINE return NEW_LINE DEDENT |
Else | while True : NEW_LINE INDENT currLength = tree [ temp ] . length NEW_LINE if ( currIndex - currLength >= 1 and s [ currIndex ] == s [ currIndex - currLength - 1 ] ) : NEW_LINE INDENT break NEW_LINE DEDENT temp = tree [ temp ] . suffixEdge NEW_LINE DEDENT tree [ currNode ] . suffixEdge = tree [ temp ] . insertionEdge [ ord ( s [ currIndex ] ) - ord ( ' a ' ) ] NEW_LINE |
Driver code | if __name__ == " _ _ main _ _ " : NEW_LINE INDENT MAXN = 1000 NEW_LINE DEDENT |
Imaginary root 's suffix edge points to itself, since for an imaginary string of length = -1 has an imaginary suffix string. Imaginary root. | root1 = Node ( - 1 , 1 ) NEW_LINE |
NULL root 's suffix edge points to Imaginary root, since for a string of length = 0 has an imaginary suffix string. | root2 = Node ( 0 , 1 ) NEW_LINE |
last will be the index of our last substring | last = ptr NEW_LINE for i in range ( tree [ last ] . start , tree [ last ] . end + 1 ) : NEW_LINE INDENT print ( s [ i ] , end = " " ) NEW_LINE DEDENT |
Find the missing number in a range | def missingNum ( arr , n ) : NEW_LINE INDENT minvalue = min ( arr ) NEW_LINE DEDENT |
here we xor of all the number | xornum = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT xornum ^= ( minvalue ) ^ arr [ i ] NEW_LINE minvalue = minvalue + 1 NEW_LINE DEDENT |
xor last number | return xornum ^ minvalue NEW_LINE |
Driver method | arr = [ 13 , 12 , 11 , 15 ] NEW_LINE n = len ( arr ) NEW_LINE print ( missingNum ( arr , n ) ) NEW_LINE |
Returns last index of x if it is present . Else returns - 1. | def findLastIndex ( str , x ) : NEW_LINE INDENT index = - 1 NEW_LINE for i in range ( 0 , len ( str ) ) : NEW_LINE INDENT if str [ i ] == x : NEW_LINE INDENT index = i NEW_LINE DEDENT DEDENT return index NEW_LINE DEDENT |
String in which char is to be found | str = " geeksforgeeks " NEW_LINE |
char whose index is to be found | x = ' e ' NEW_LINE index = findLastIndex ( str , x ) NEW_LINE if index == - 1 : NEW_LINE INDENT print ( " Character β not β found " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' Last β index β is ' , index ) NEW_LINE DEDENT |
Returns last index of x if it is present . Else returns - 1. | def findLastIndex ( str , x ) : NEW_LINE |
Traverse from right | for i in range ( len ( str ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( str [ i ] == x ) : NEW_LINE INDENT return i NEW_LINE DEDENT DEDENT return - 1 NEW_LINE |
Driver code | str = " geeksforgeeks " NEW_LINE x = ' e ' NEW_LINE index = findLastIndex ( str , x ) NEW_LINE if ( index == - 1 ) : NEW_LINE INDENT print ( " Character β not β found " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Last β index β is β " , index ) NEW_LINE DEDENT |
Returns smallest number whose set bits are maximum in given range . | def countMaxSetBits ( left , right ) : NEW_LINE INDENT while ( left | ( left + 1 ) ) <= right : NEW_LINE INDENT left |= left + 1 NEW_LINE DEDENT return left NEW_LINE DEDENT |
driver code | l = 1 NEW_LINE r = 5 NEW_LINE print ( countMaxSetBits ( l , r ) ) NEW_LINE l = 1 NEW_LINE r = 10 NEW_LINE print ( countMaxSetBits ( l , r ) ) NEW_LINE |
Python3 code to find the largest value smaller than or equal to N | class newNode : NEW_LINE |
To create new BST Node | def __init__ ( self , item ) : NEW_LINE INDENT self . key = item NEW_LINE self . left = None NEW_LINE self . right = None NEW_LINE DEDENT |
To insert a new node in BST | def insert ( node , key ) : NEW_LINE |
If tree is empty return new node | if ( node == None ) : NEW_LINE INDENT return newNode ( key ) NEW_LINE DEDENT |
If key is less then or greater then node value then recur down the tree | if ( key < node . key ) : NEW_LINE INDENT node . left = insert ( node . left , key ) NEW_LINE DEDENT elif ( key > node . key ) : NEW_LINE INDENT node . right = insert ( node . right , key ) NEW_LINE DEDENT |
Return the ( unchanged ) node pointer | return node NEW_LINE |
Returns largest value smaller than or equal to key . If key is smaller than the smallest , it returns - 1. | def findFloor ( root , key ) : NEW_LINE INDENT curr = root NEW_LINE ans = None NEW_LINE while ( curr ) : NEW_LINE INDENT if ( curr . key <= key ) : NEW_LINE INDENT ans = curr NEW_LINE curr = curr . right NEW_LINE DEDENT else : NEW_LINE INDENT curr = curr . left NEW_LINE DEDENT DEDENT if ( ans ) : NEW_LINE INDENT return ans . key NEW_LINE DEDENT return - 1 NEW_LINE DEDENT |
Driver code | if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 25 NEW_LINE root = None NEW_LINE root = insert ( root , 19 ) NEW_LINE insert ( root , 2 ) NEW_LINE insert ( root , 1 ) NEW_LINE insert ( root , 3 ) NEW_LINE insert ( root , 12 ) NEW_LINE insert ( root , 9 ) NEW_LINE insert ( root , 21 ) NEW_LINE insert ( root , 19 ) NEW_LINE insert ( root , 25 ) NEW_LINE print ( findFloor ( root , N ) ) NEW_LINE DEDENT |
Function to find no . of elements to be added to get s | def findS ( s ) : NEW_LINE INDENT l = 1 NEW_LINE r = int ( s / 2 ) + 1 NEW_LINE DEDENT |
Apply Binary search | while ( l <= r ) : NEW_LINE |
Find mid | mid = int ( ( l + r ) / 2 ) NEW_LINE |
find sum of 1 to mid natural numbers using formula | sum = int ( mid * ( mid + 1 ) / 2 ) NEW_LINE |
If sum is equal to n return mid | if ( sum == s ) : NEW_LINE INDENT return mid NEW_LINE DEDENT |
If greater than n do r = mid - 1 | elif ( sum > s ) : NEW_LINE INDENT r = mid - 1 NEW_LINE DEDENT |
else do l = mid + 1 | else : NEW_LINE INDENT l = mid + 1 NEW_LINE DEDENT |
If not possible , return - 1 | return - 1 NEW_LINE |
Drivers code | s = 15 NEW_LINE n = findS ( s ) NEW_LINE if ( n == - 1 ) : NEW_LINE INDENT print ( " - 1" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( n ) NEW_LINE DEDENT |
Compare two string equals are not | def compareStrings ( str1 , str2 ) : NEW_LINE INDENT i = 0 NEW_LINE while i < len ( str1 ) - 1 and str1 [ i ] == str2 [ i ] : NEW_LINE INDENT i += 1 NEW_LINE DEDENT if str1 [ i ] > str2 [ i ] : NEW_LINE INDENT return - 1 NEW_LINE DEDENT return str1 [ i ] < str2 [ i ] NEW_LINE DEDENT |
Main function to find string location | def searchStr ( arr , string , first , last ) : NEW_LINE INDENT if first > last : NEW_LINE INDENT return - 1 NEW_LINE DEDENT DEDENT |
Move mid to the middle | mid = ( last + first ) // 2 NEW_LINE |
If mid is empty , find closest non - empty string | if len ( arr [ mid ] ) == 0 : NEW_LINE |
If mid is empty , search in both sides of mid and find the closest non - empty string , and set mid accordingly . | left , right = mid - 1 , mid + 1 NEW_LINE while True : NEW_LINE INDENT if left < first and right > last : NEW_LINE INDENT return - 1 NEW_LINE DEDENT if right <= last and len ( arr [ right ] ) != 0 : NEW_LINE INDENT mid = right NEW_LINE break NEW_LINE DEDENT if left >= first and len ( arr [ left ] ) != 0 : NEW_LINE INDENT mid = left NEW_LINE break NEW_LINE DEDENT right += 1 NEW_LINE left -= 1 NEW_LINE DEDENT |
If str is found at mid | if compareStrings ( string , arr [ mid ] ) == 0 : NEW_LINE INDENT return mid NEW_LINE DEDENT |
If str is greater than mid | if compareStrings ( string , arr [ mid ] ) < 0 : NEW_LINE INDENT return searchStr ( arr , string , mid + 1 , last ) NEW_LINE DEDENT |
If str is smaller than mid | return searchStr ( arr , string , first , mid - 1 ) NEW_LINE |
Driver Code | if __name__ == " _ _ main _ _ " : NEW_LINE |
Input arr of Strings . | arr = [ " for " , " " , " " , " " , " geeks " , " ide " , " " , " practice " , " " , " " , " quiz " , " " , " " ] NEW_LINE |
input Search String | string = " quiz " NEW_LINE n = len ( arr ) NEW_LINE print ( searchStr ( arr , string , 0 , n - 1 ) ) NEW_LINE |
Function to sort the given string in decreasing order by removing the non adjacent characters | def canSortString ( S , N ) : NEW_LINE |
Keeps the track whether the string can be sorted or not | flag = 1 NEW_LINE |
Traverse the given string S | i = N - 2 NEW_LINE while ( i >= 0 ) : NEW_LINE |
Check if S [ i ] and S [ i + 1 ] are both '1 | ' NEW_LINE INDENT if ( S [ i ] == '1' and S [ i + 1 ] == '1' ) : NEW_LINE INDENT break NEW_LINE DEDENT i -= 1 NEW_LINE DEDENT |
Traverse the string S from the indices i to 0 | j = i NEW_LINE while ( j >= 0 ) : NEW_LINE |
If S [ j ] and S [ j + 1 ] is equal to 0 | if ( S [ j ] == '0' and S [ j + 1 ] == '0' ) : NEW_LINE |
Mark flag false | flag = 0 NEW_LINE break NEW_LINE j -= 1 NEW_LINE |
If flag is 0 , then it is not possible to sort the string | if ( flag == 0 ) : NEW_LINE INDENT return " No " NEW_LINE DEDENT |
Otherwise | else : NEW_LINE INDENT return " Yes " NEW_LINE DEDENT |
Driver Code | if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = "10101011011" NEW_LINE N = len ( S ) NEW_LINE print ( canSortString ( S , N ) ) NEW_LINE DEDENT |
Function to find the maximum sum of MEX of prefix arrays for any arrangement of the given array | def maximumMex ( arr , N ) : NEW_LINE |
Stores the final arrangement | ans = [ ] NEW_LINE |
Sort the array in increasing order | arr = sorted ( arr ) NEW_LINE |
Iterate over the array arr [ ] | for i in range ( N ) : NEW_LINE INDENT if ( i == 0 or arr [ i ] != arr [ i - 1 ] ) : NEW_LINE INDENT ans . append ( arr [ i ] ) NEW_LINE DEDENT DEDENT |
Iterate over the array , arr [ ] and push the remaining occurrences of the elements into ans [ ] | for i in range ( N ) : NEW_LINE INDENT if ( i > 0 and arr [ i ] == arr [ i - 1 ] ) : NEW_LINE INDENT ans . append ( arr [ i ] ) NEW_LINE DEDENT DEDENT |
Prthe array , ans [ ] | for i in range ( N ) : NEW_LINE INDENT print ( ans [ i ] , end = " β " ) NEW_LINE DEDENT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.