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 uniquePathsBruteForce(self, m: int, n: int) -> int: | |
grid = [[""] * m for _ in range(n)] | |
def up(grd): | |
if len(grd) == 0: | |
return 0 | |
# the last cell | |
elif len(grd) == 1 and len(grd[0]) == 0: | |
return 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
from typing import List | |
class Solution: | |
def __init__(self): | |
self.letter_dict = {"2": "abc", "3": "def", "4": "ghi", "5": "jkl", "6": "mno", "7": "pqrs", "8": "tuv", "9": "wxyz"} | |
def letterCombinations(self, digits: str) -> List[str]: | |
if digits == "" or len(digits) == 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 flatten(accumulator, lst): | |
if len(lst) == 0: | |
return accumulator | |
elif type(lst[0]) is list: | |
result = flatten([], lst[0]) | |
return flatten(accumulator + result, lst[1:]) | |
else: | |
accumulator.append(lst[0]) | |
return flatten(accumulator, lst[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
import java.util.*; | |
import java.math.*; | |
public class LCS { | |
public static void main(String[] args) { | |
LCS_ l = new LCS_(); | |
System.out.println(l.lCSR("AGGTAB", "GXTXAYB", 0, 0)); | |
System.out.println(l.lCSR("pmjghexybyrgzczy", "hafcdqbgncrcbihkd", 0, 0)); | |
System.out.println(l.lCSR("oxcpqrsvwf","shmtulqrypy", 0, 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
//geeksforgeeks.org/find-if-there-is-a-subarray-with-0-sum/ | |
import java.util.ArrayList; | |
public class PrefixSum { | |
public static int[] recoverOriginalArray(int[] array) { | |
int l = array.length; | |
int[] result = new int[l]; | |
result[0] = array[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
public class PrefixSumArray { | |
public static int[][] prefixSumArray(int[] array) { | |
int al = array.length; | |
int[][] result = new int[al][al]; | |
int sum = 0; | |
for(int i = 0; i < al; i++) { | |
for(int j = i; j < al; j++) { | |
sum += array[j]; | |
result[i][j] = sum; |
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
/* | |
* | |
* Given a array and a number k, find all contigious array sequences that are divisible by k | |
* | |
* | |
* | |
*/ | |
public class KSubsequences { |
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
(defparameter init-tree | |
'((a) (b) (c) (d) (e) (f) (g) (h) (i) | |
(j) (k) (l) (m) (n) (o) (p) (q) (r) | |
(s) (t) (u) (v) (w) (x) (y) (z))) | |
(defun add-member (m seq) | |
(labels ((am (m lst acc found) | |
(cond | |
((null lst) | |
(if (null found) |
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
my Bool $highs_only = False; | |
my Bool $lows_only = True; | |
my Str @notes; | |
if $highs_only { | |
@notes = <C C# D Eb E F F# G G# A Bb B>; | |
} elsif $lows_only { | |
@notes = <Low-C Low-C# Low-D Low-Eb Low-E Low-F Low-F# Low-G Low-G# Low-A Low-Bb Low-B>; | |
} else { | |
@notes = <C C# D Eb E F F# G G# A Bb B Low-C Low-C# Low-D Low-Eb Low-E Low-F Low-F# Low-G Low-G# Low-A Low-Bb Low-B>; |
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
# | |
# This program scrapes the FIFA Data from the site: | |
# http://thesoccerworldcups.com/index.php | |
# | |
# | |
import urllib2 |
NewerOlder