Skip to content

Instantly share code, notes, and snippets.

View jan25's full-sized avatar
🎯
Focusing

Abhilash Gnan jan25

🎯
Focusing
View GitHub Profile
class Solution:
def __init__(self, N, blacklist):
blacklist.sort()
self.N = N - len(blacklist)
self.free_pairs = self.prep_free_pairs(N, blacklist)
self.offsets = [0]
for pair in self.free_pairs:
self.offsets.append(pair[1] - pair[0] + 1)
self.offsets[-1] += self.offsets[-2]
class Solution:
def largestComponentSize(self, A):
return self.figure_components(A, self.sieve())
def sieve(self):
range_max = 100001
sieve_array = [-1] * range_max
for i in range(2, range_max):
for j in range(i, range_max, i):
if sieve_array[j] == -1: sieve_array[j] = i
class Solution:
def removeStones(self, stones):
t = [-1] * len(stones)
xs, ys = {}, {}
for i, p in enumerate(stones):
x, y = p
if x in xs: self.onion(xs[x], i, t)
else: xs[x] = i
if y in ys: self.onion(ys[y], i, t)
else: ys[y] = i
'''
https://leetcode.com/problems/burst-balloons/description/
'''
class Solution:
def maxCoins(self, nums):
nums = [1, *nums, 1]
return self.dp(0, len(nums) - 1, nums, {})
def dp(self, a, b, nums, memo):
if abs(a - b) < 2: return 0
nums = [ "569815571556", "4938532894754", "1234567", "472844278465445" ]
def get_lotter_nums_rec_helper(curr_num, curr_n, rem_str):
if curr_num > 0 and curr_num < 60:
lottery_nums = get_lottery_nums_rec(curr_n - 1, rem_str)
if lottery_nums:
return [curr_num] + lottery_nums
def get_lottery_nums_rec(n, s):
if n == 0 and s == '': return [' ']
@jan25
jan25 / lottery.py
Last active July 7, 2018 09:22
spaces fix
nums = [ "569815571556", "4938532894754", "1234567", "472844278465445" ]
def get_lotter_nums_rec_helper(curr_num, curr_n, rem_str):
if curr_num > 0 and curr_num < 60:
lottery_nums = get_lottery_nums_rec(curr_n - 1, rem_str)
if lottery_nums:
return [curr_num] + lottery_nums
def get_lottery_nums_rec(n, s):
if n == 0 and s == '': return [' ']
def callAll():
result = True
result = A() and result
result = B() and result
# so on
return result