This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/python3 | |
| import math | |
| import os | |
| import random | |
| import re | |
| import sys | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/python3 | |
| import math | |
| import os | |
| import random | |
| import re | |
| import sys | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/python3 | |
| import math | |
| import os | |
| import random | |
| import re | |
| import sys | |
| # | |
| # Complete the 'almostSorted' function below. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def pairs(k, arr): | |
| # Write your code here | |
| cnt = 0 | |
| for i in range(len(arr)-1): | |
| for j in range(i+1,len(arr)): | |
| if abs(arr[i] - arr[j]) == k: | |
| cnt+=1 | |
| return cnt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def truckTour(petrolpumps): | |
| # Write your code here | |
| a=[] | |
| for i in range(len(petrolpumps)): | |
| a.append(petrolpumps[i][0] - petrolpumps[i][1]) | |
| sum = 0 | |
| fin = 0 | |
| shift = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def removeDuplicates(head): | |
| # Write your code here | |
| node = head | |
| while node.next: | |
| _next = node.next | |
| if node.data == _next.data: | |
| node.next = _next.next | |
| else: | |
| node = _next | |
| return head |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def bigSorting(unsorted): | |
| return sorted(unsorted, key=lambda x: int(x)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # DON'T USE. IT FAILS FOR TWO CASES(2/15) | |
| def palindromeIndex(s): | |
| # Write your code here | |
| r = s[::-1] | |
| if r == s: | |
| return -1 | |
| for i in range(len(s)): | |
| j = len(s) - 1-i | |
| ss = s[:i]+s[i+1:] | |
| rr = r[:j]+r[j+1:] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def anagram(s): | |
| # Write your code here | |
| if len(s) %2 !=0: | |
| return -1 | |
| l = len(s)//2 | |
| a,b = s[:l],s[l:] | |
| m,n={},{} | |
| for i in range(l): | |
| if a[i] not in m: | |
| m[a[i]] = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def twoArrays(k, A, B): | |
| # Write your code here | |
| # if (min(A) + max(B) < k) or (min(B) + max(A) < k): | |
| # return "NO" | |
| # return "YES" | |
| A.sort() | |
| B.sort() | |
| B = B[::-1] | |
| for a,b in zip(A,B): |