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
| #User function Template for python3 | |
| from collections import deque | |
| class Solution: | |
| def addBinary(self, A, B): | |
| # code here | |
| len1 = len(A) | |
| len2 = len(B) | |
| carry = 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
| # Holloumi Boxes | |
| # logic | |
| def can_sort_it(a, n, k) -> bool: | |
| # def reverse(a, ptr1, ptr2): | |
| # a[ptr1:ptr2] = reversed(a[ptr1:ptr2]) | |
| # if n == 1: | |
| # return True |
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
| # logic | |
| def can_take_the_trip() -> int: | |
| """ | |
| logic: | |
| calculate gaps between each petrol stations, the max gap is the minimum fuel(1unit = 1lt) needed to complete the trip | |
| """ | |
| n, x = map(int, input().split()) | |
| petrol_stations = list(map(int, input().split())) | |
| # approach 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
| # Cover in Water | |
| import re | |
| def cover_in_water(): | |
| n = int(input()) | |
| s = input() | |
| # logic here |
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 game_with_integer() -> str: | |
| n = int(input()) | |
| if n % 3 == 0: | |
| return "Second" | |
| else: | |
| return "First" | |
| t = int(input()) | |
| for _ in range(t): |
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
| class Solution: | |
| def isHappy(self, n: int) -> bool: | |
| def get_sum_of_squares_of_digits(n) -> int: | |
| res = 0 | |
| while n != 0: | |
| res += (n % 10) ** 2 | |
| n //= 10 | |
| return res | |
| visited = set() |
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
| class Solution: | |
| def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool: | |
| n = len(nums) | |
| # approach-1: brute force | |
| # for i in range(n-1): | |
| # for j in range(i+1, n): | |
| # if abs(i-j) <= k and nums[i] == nums[j]: | |
| # return True |
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 jagged_swaps(): | |
| n = int(input()) | |
| a = list(map(int, input().split())) | |
| if a[0] == 1: | |
| return "YES" | |
| return "NO" | |
| """Actual sorting logic if a[0] == 1""" | |
| # upper_bound = n |
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 doremys_paint(): | |
| n = int(input()) | |
| a = list(map(int, input().split())) | |
| # logic here | |
| """ | |
| case1: if there is only 1 unique element, return 'YES' | |
| case2: if there is 2 unique elements, and if any one element's count/frequency == n/2, | |
| return 'YES' or 'NO' otherwise | |
| case 3: if there is more than 2 unique elements return 'NO' |
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 dont_try_to_count(): | |
| n, m = map(int, input().split()) | |
| x = input() | |
| s = input() | |
| """Approach 1""" | |
| # operations = 0 | |
| # while len(x) <= n * m: | |
| # if s in x: | |
| # return operations |
OlderNewer