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 pickingNumbers(arr): | |
| maximum = 0 | |
| for number in arr: | |
| freq = arr.count(number) + arr.count(number-1) | |
| if freq > maximum: | |
| maximum = freq | |
| return maximum |
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 getTotalX(a, b): | |
| maxN = max(b) | |
| minN = min(a) | |
| sumN = 0 | |
| for number in range(minN, maxN+1): | |
| factorsOfNumber = all([number%x == 0 for x in a]) | |
| multsOfNumber = all([x%number == 0 for x in b]) | |
| sumN += factorsOfNumber * multsOfNumber | |
| return sumN |
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
| toys, budget = [int(x) for x in input().strip().split()] | |
| spent = 0 | |
| bought = 0 | |
| prices = [int(x) for x in input().strip().split()] | |
| prices.sort() | |
| for price in prices: | |
| if spent + price <= budget: |
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
| q = int(input()) | |
| while(q>0): | |
| q -= 1 | |
| letters = [c for c in input().strip()] | |
| cleaned = [] | |
| cleaned.append(letters[0]) | |
| for letter in letters[1:]: | |
| if letter != cleaned[-1]: | |
| cleaned.append(letter) |
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 countSwaps(a): | |
| swaps = 0 | |
| n = len(a) | |
| for i in range(n): | |
| for j in range(n-1): | |
| # Swap adjacent elements if they are in decreasing order | |
| if a[j] > a[j + 1]: | |
| a[j], a[j + 1] = a[j+1], a[j] | |
| swaps += 1 | |
| print("Array is sorted in", swaps, "swaps.") |
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 | |
| first_multiple_input = input().rstrip().split() |
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
| from collections import Counter | |
| def freqQuery(queries): | |
| items = Counter() | |
| checks = Counter() | |
| res = [] | |
| for couple in queries: | |
| query, item = couple | |
| if query == 1: | |
| checks[items[item]] -= 1 | |
| items[item] += 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 binary_search(list, item): | |
| low = 0 | |
| high = len(list)-1 | |
| while low <= high: | |
| mid = (low + high) // 2 | |
| guess = list[mid] | |
| if guess == item: | |
| return mid | |
| elif guess > item: |
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
| pairs = int(input()) | |
| from collections import Counter | |
| def checkPairs(first, second): | |
| firstCount = Counter(first) | |
| secondCount = Counter(second) | |
| commonLettersExist = firstCount - secondCount != firstCount | |
| if commonLettersExist: | |
| return "YES" |
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
| # Using Counter | |
| # see https://www.journaldev.com/20806/python-counter-python-collections-counter#python-counter-arithmetic-operations | |
| # (Counter(note) - Counter(magazine)) returns only the elements with a positive count | |
| # That is, if there are more less in `note` than `magazine`, we would get an empty dictionary. | |
| from collections import Counter | |
| def checkMagazine(magazine, note): | |
| if (Counter(note) - Counter(magazine)) == {}: | |
| print("Yes") | |
| else: | |
| print("No") |