This file contains 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(object): | |
def solve(self, n, k): | |
if n == 1: | |
return 1 | |
else: | |
return (self.solve(n - 1, k) + k - 1) % n + 1 | |
This file contains 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(object): | |
combinations = set() | |
def solve(self, arr, n): | |
self.helper(0, [], 0, n, arr) | |
return list(self.combinations) | |
def helper(self, start_index, current_comb, current_sum, sum, arr): |
This file contains 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, defaultdict | |
class Solution(object): | |
def solve(self, s1, s2): | |
s1 = list(s1) | |
s2 = list(s2) |
This file contains 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(object): | |
def solve(self, s): | |
vowels = {"a", "e", "i", "o", "u", "A", "E", "I", "O", "U"} | |
ans = 0 | |
for i, c in enumerate(s): | |
if c in vowels: |
This file contains 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(object): | |
count = [] | |
def solve(self, s): | |
self.helper(s, 0, 0, 0, []) | |
addresses = [] | |
for a in self.count: | |
prev = None | |
add = None |
This file contains 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(object): | |
def solution(self, a): | |
count = 0 | |
ele = None | |
for n in a: | |
if ele is None: | |
count = 1 | |
ele = n |
This file contains 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(object): | |
def solve(self, a): | |
candies = [1 for i in a] | |
n = len(a) | |
# first pass | |
for i in range(1, n): | |
if a[i] > a[i-1]: | |
candies[i] = candies[i-1] + 1 |
This file contains 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(object): | |
def solve(self, a): | |
is_flip_on = False | |
flips = 0 | |
for n in a: | |
if not is_flip_on and n == 1: | |
continue | |
elif is_flip_on and n == 0: |
This file contains 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(object): | |
def solution(self, a): | |
seen = {} | |
cycles = [] | |
for i, n in enumerate(a): |
This file contains 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
""" | |
https://scammingthecodinginterview.com | |
Week 7: Dynamic Programming | |
Problem: 1 | |
""" | |
class Solution(object): | |
def solve(self, a, b): | |
n = len(a) | |
m = len(b) |