blob_id
stringlengths
40
40
repo_name
stringlengths
5
127
path
stringlengths
2
523
length_bytes
int64
22
545k
score
float64
3.5
5.34
int_score
int64
4
5
text
stringlengths
22
545k
bbf45532ab46317e7c548a735d5a2663e074b126
OPEOStudio/kraft_bootstrap
/print_request.py
1,268
3.65625
4
import requests import json ### PRINT THE REQUEST # Script to print the request, to make sure that all the right request elements are being sent # DOESN'T WORK FOR NOW def print_r(string, url, data, headers, params): # Put headers, params back into dictionnary #print("headers: "+headers) ## Allowed me to test that ...
950c9369f7bb2ee031290a62649306918dc364b4
ThembaMbulwana/Getting_to_know_python
/js_functions.py
1,359
3.875
4
def list_all_js_function_names(path_to_js_file): """ path_to_js_file is a path to a file on your hard drive This function will read the entire input file and then return a list of js function names as strings """ func_names = [] start_row_list =[] end_row_list = [] with open(path_to...
62a8497e0e8cb5bd0f5d8b6f832fbae1be2ff945
sunanthas9/PyTorch_Tutorials
/example8.py
1,858
3.875
4
# If we plan to use custom modules for certain layers, those could be defined using the nn package prior to defining the model sequence. # This examples shows the same two-layer network as a custom function import torch class TwoLayerNet(torch.nn.Module): def __init__(self, D_in, H, D_out): """ In the constructo...
830453f036ba93323aac6b95d0d10477d56920a3
jakehoare/leetcode
/python_1001_to_2000/1220_Count_Vowels_Permutation.py
1,480
3.734375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/count-vowels-permutation/ # Given an integer n, your task is to count how many strings of length n can be formed under the following rules: # Each character is a lower case vowel ('a', 'e', 'i', 'o', 'u') # Each vowel 'a' may only be followed by ...
1004496c01632f61921338146b1ef51aee666344
jakehoare/leetcode
/python_1_to_1000/333_Largest_BST_Subtree.py
1,625
3.984375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/largest-bst-subtree/ # Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest means subtree # with largest number of nodes in it. # Bottom-up recursively determine whether a subtree is a BST if its child...
f1adcb93bd26dbc47da1b70b7088ab90daf60f98
jakehoare/leetcode
/python_1001_to_2000/1283_Find_the_Smallest_Divisor_Given_a_Threshold.py
1,493
3.765625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold/ # Given an array of integers nums and an integer threshold, # we will choose a positive integer divisor and divide all the array by it and sum the result of the division. # Find the smallest divisor su...
82de385c1981a3d60d5da46b7531a4d11684aca8
jakehoare/leetcode
/python_1_to_1000/477_Total_Hamming_Diatance.py
944
4.09375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/total-hamming-distance/ # The Hamming distance between two integers is the number of positions at which the corresponding bits are different. # Now your job is to find the total Hamming distance between all pairs of the given numbers. # For each...
b96de09b9f67d3e58ecd894e2d3eb202f772d4c4
jakehoare/leetcode
/python_1_to_1000/544_Output_Contest_Matches.py
1,645
3.6875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/output-contest-matches/ # During the NBA playoffs, we always arrange the rather strong team to play with the rather weak team, like make the # rank 1 team play with the rank nth team, which is a good strategy to make the contest more interesting....
d3e80f583ee12fb368a9a31e2217d6edc23babb0
jakehoare/leetcode
/python_1_to_1000/548_Split_Array_with_Equal_Sum.py
1,802
3.53125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/split-array-with-equal-sum/ # Given an array with n integers, you need to find if there are triplets (i, j, k) which satisfies following conditions: # 0 < i, i + 1 < j, j + 1 < k < n - 1 # Sum of subarrays (0, i - 1), (i + 1, j - 1), (j + 1, k - ...
da7b4e515406b0cbf3689b35eb06ea05cef7f9a8
jakehoare/leetcode
/python_1001_to_2000/1185_Day_of_the_Week.py
1,400
4.0625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/day-of-the-week/ # Given a date, return the corresponding day of the week for that date. # The input is given as three integers representing the day, month and year respectively. # Return the answer as one of the following values {"Sunday", "Mond...
66c00b57b5cfd3f77e7cac2ec77565bd22f968f1
jakehoare/leetcode
/python_1_to_1000/783_Minimum_Distance_Between_BST_Nodes.py
917
3.875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/minimum-distance-between-bst-nodes/ # Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any # two different nodes in the tree. # Inorder traversal visits nodes in increasing order of va...
ebbdf1418891290977e68264e0745dff3c18716f
jakehoare/leetcode
/python_1_to_1000/379_Design_Phone_Directory.py
1,514
3.828125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/design-phone-directory/ # Design a Phone Directory which supports the following operations: # get: Provide a number which is not assigned to anyone. # check: Check if a number is available or not. # release: Recycle or release a number. # Store ...
d9d46d26c56a62517ded068c5d9a7c342d449a8a
jakehoare/leetcode
/python_1_to_1000/911_Online_Election.py
2,171
3.53125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/online-election/ # In an election, the i-th vote was cast for persons[i] at time times[i]. # Now, we would like to implement the following query function: TopVotedCandidate.q(int t) will return the number # of the person that was leading the elec...
99f0aff472734a904a1b9d80a88463117379b0c5
jakehoare/leetcode
/python_1001_to_2000/1088_Confusing_Number_II.py
1,530
4
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/confusing-number-ii/ # We can rotate digits by 180 degrees to form new digits. # When 0, 1, 6, 8, 9 are rotated 180 degrees, they become 0, 1, 9, 8, 6 respectively. # When 2, 3, 4, 5 and 7 are rotated 180 degrees, they become invalid. # A confusi...
b4be11ac7af53ac94a422bfba1accbd8557fdc46
jakehoare/leetcode
/python_1_to_1000/354_Russian_Doll_Envelopes.py
2,407
4.25
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/russian-doll-envelopes/ # You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envelope can fit # into another if and only if both the width and height of one envelope is greater than the width and height...
7a5d515a801a4e06eaafa0622f5b4d3e962ea0f0
jakehoare/leetcode
/python_1_to_1000/853_Car_Fleet.py
1,711
4
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/car-fleet/ # N cars are going to the same destination along a one lane road. The destination is target miles away. # Each car i has a constant speed speed[i] (in miles per hour), and initial position position[i] miles towards the # target along ...
8b9ea814605ce85ab31ea9bd73aca1ddb5e7bad3
jakehoare/leetcode
/python_1_to_1000/831_Masking_Personal_Information.py
2,738
4.21875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/masking-personal-information/ # We are given a personal information string S, which may represent either an email address or a phone number. # We would like to mask this personal information according to the following rules: # 1. Email address: #...
0ff9cfd4ae69a8ee55cfb09ac74fd3f0d3167a8c
jakehoare/leetcode
/python_1_to_1000/576_Out_of_Boundary_Paths.py
2,723
3.703125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/out-of-boundary-paths/ # There is an m by n grid with a ball. Given the start coordinate (i,j) of the ball, you can move the ball to adjacent # cell or cross the grid boundary in four directions (up, down, left, right). However, you can at most m...
8067b1cb8a4865505520444be08a9d0f74b9f399
jakehoare/leetcode
/python_1_to_1000/857_Minimum_Cost_to_Hire_K_Workers.py
1,960
3.75
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/minimum-cost-to-hire-k-workers/ # There are N workers. The i-th worker has a quality[i] and a minimum wage expectation wage[i]. # Now we want to hire exactly K workers to form a paid group. # When hiring a group of K workers, we must pay them ac...
b83a25d55f9aac1b23550bb1cdb6a305b0c726a8
jakehoare/leetcode
/python_1_to_1000/648_Replace_Words.py
2,160
4.03125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/replace-words/ # In English, we have a concept called root, which can be followed by some other words to form another longer word - # let's call this word successor. For example, the root an, followed by other, which can form another word another...
143761befef27bde3fa583eda67c15c9bcb2ce46
jakehoare/leetcode
/python_1001_to_2000/1030_Matrix_Cells_in_Distance_Order.py
1,819
3.859375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/matrix-cells-in-distance-order/ # We are given a matrix with R rows and C columns has cells with integer coordinates (r, c), # where 0 <= r < R and 0 <= c < C. # Additionally, we are given a cell in that matrix with coordinates (r0, c0). # Return...
1306dcc158a0a1cd716bbe5da880d1a4ba9b8d2d
jakehoare/leetcode
/python_1001_to_2000/1228_Missing_Number_In_Arithmetic_Progression.py
1,014
3.59375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/missing-number-in-arithmetic-progression/ # In some array arr, the values were in arithmetic progression: # the values arr[i+1] - arr[i] are all equal for every 0 <= i < arr.length - 1. # Then, a value from arr was removed that was not the first ...
a15a9664cfdb3ab2b29be58fa6a81b226fbd5319
jakehoare/leetcode
/python_1_to_1000/520_Detect_Capital.py
1,272
4.125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/detect-capital/ # Given a word, you need to judge whether the usage of capitals in it is right or not. # We define the usage of capitals in a word to be right when one of the following cases holds: # All letters in this word are capitals, like "U...
12cc2a9c7ac7d7ccfdb7fed3f21ebecea9565689
jakehoare/leetcode
/python_1_to_1000/688_Knight_Probability_in_Chessboard.py
2,864
3.703125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/knight-probability-in-chessboard/ # On an NxN chessboard, a knight starts at the r-th row and c-th column and attempts to make exactly K moves. # The rows and columns are 0 indexed, so the top-left square is (0, 0), and the bottom-right square is...
0984ea8a5fd03c00f42614cfe5f1cf68286d9520
jakehoare/leetcode
/python_1_to_1000/780_Reaching_Points.py
1,350
3.859375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/reaching-points/ # A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y). # Given a starting point (sx, sy) and a target point (tx, ty), return True if and only if a sequence of moves # exists to transform th...
cf32dfbb26e0c27f7f47d26004c86853f371f9d8
jakehoare/leetcode
/python_1_to_1000/670_Maximum_Swap.py
1,783
3.890625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/maximum-swap/ # Given a non-negative integer, you could swap two digits at most once to get the maximum valued number. # Return the maximum valued number you could get. # Iterate backwards from the least to the most significant digit. When we ha...
ad3020eeb117370258e782bb48b77d36055790eb
jakehoare/leetcode
/python_1_to_1000/455_Assign_Cookies.py
1,404
3.765625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/assign-cookies/ # Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at # most one cookie. Each child i has a greed factor gi, which is the minimum size of a cookie that the child will be...
c7531deb5affbcc2c66304746f53f4e844ad7c88
jakehoare/leetcode
/python_1001_to_2000/1161_Maximum_Level_Sum_of_a_Binary_Tree.py
1,133
3.953125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree/ # Given the root of a binary tree, the level of its root is 1, the level of its children is 2, and so on. # Return the smallest level X such that the sum of all the values of nodes at level X is maximal. # Tra...
9093cc0a54bc5cce384cfafa0140afa0927e7a1b
jakehoare/leetcode
/python_1_to_1000/039_Combination_Sum.py
1,346
3.5625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/combination-sum/ # Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. # The same repeated number may be chosen from C unlimited number of times. # All numbers (in...
111af841f1d37c607cb77f9aa28653561c31b2aa
jakehoare/leetcode
/python_1_to_1000/636_Exclusive_Time_of_Functions.py
1,856
3.625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/exclusive-time-of-functions/ # Given the running logs of n functions that are executed in a nonpreemptive single threaded CPU, find the exclusive # time of these functions. # Each function has a unique id, start from 0 to n-1. A function may be c...
53ebc02d10c754af795e15036eeb95152cd7d9c0
jakehoare/leetcode
/python_1_to_1000/529_Minesweeper.py
2,649
3.90625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/minesweeper/ # Let's play the minesweeper game (Wikipedia, online game)! # You are given a 2D char matrix representing the game board. 'M' represents an unrevealed mine, 'E' represents an # unrevealed empty square, 'B' represents a revealed blank...
1f62c4c473d60e9271249c369a0901e28a8e63b8
jakehoare/leetcode
/python_1_to_1000/045_Jump_Game_II.py
1,330
3.640625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/jump-game-ii/ # Given an array of non-negative integers, you are initially positioned at the first index of the array. # Each element in the array represents your maximum jump length at that position. # Your goal is to reach the last index in the...
204f3f2c89eb89a7b4b46e75dd4c33ff141f6e3c
jakehoare/leetcode
/python_1_to_1000/449_Serialize_and_Deserialize_BST.py
1,868
3.75
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/serialize-and-deserialize-bst/ # Design an algorithm to serialize and deserialize a binary search tree. There is no restriction on how your # serialization/deserialization algorithm should work. You just need to ensure that a binary search tree c...
60e58bb1e7ee13e1961c8bbbaa04ee0b4930523a
jakehoare/leetcode
/python_1_to_1000/514_Freedom_Trail.py
2,835
4
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/freedom-trail/ # In the video game Fallout 4, the quest "Road to Freedom" requires players to reach a metal dial called the "Freedom # Trail Ring", and use the dial to spell a specific keyword in order to open the door. # Given a string ring, whi...
d3600684f6f75bfe7275ab5c896239395a81eb57
jakehoare/leetcode
/python_1_to_1000/495_Teemo_Attacking.py
1,015
3.625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/teemo-attacking/ # In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. # Now, given the Teemo's attacking ascending time series towards Ashe and the poisoning time duration per Teemo's # ...
cd84e5efb3e296c930c3048d340d0bbc2c80c180
jakehoare/leetcode
/python_1_to_1000/641_Design_Circular_Deque.py
3,427
4.1875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/design-circular-deque/ # Design your implementation of the circular double-ended queue (deque). # Your implementation should support following operations: # MyCircularDeque(k): Constructor, set the size of the deque to be k. # insertFront(): Adds...
7a4828786bf7ec7ea8c94d31b257a649b0227108
jakehoare/leetcode
/python_1_to_1000/421_Maximum_XOR_of_Two_Numbers_in_an_Array.py
1,235
3.546875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/ # Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 2**31. # Find the maximum result of ai XOR aj, where 0 ≤ i, j < n. # Starting from prefix of 1st bit, create a set of all prefixes...
55587b271339680bb78655639c4390aef37af616
jakehoare/leetcode
/python_1_to_1000/700_Search_in_a_Binary_Search_Tree.py
933
3.90625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/search-in-a-binary-search-tree/ # Given the root node of a binary search tree (BST) and a value. # You need to find the node in the BST that the node's value equals the given value. # Return the subtree rooted with that node. If such node doesn't...
87682aabf23bc8a6ff15a86641cc8c7b8382dcb1
jakehoare/leetcode
/python_1_to_1000/647_Palindromic_Substrings.py
896
3.921875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/palindromic-substrings/ # Given a string, your task is to count how many palindromic substrings in this string. The substrings with different # start indexes or end indexes are counted as different substrings even they consist of same characters....
6947cd9886e0e2bdc122360f9a471217d2a8b655
jakehoare/leetcode
/python_1_to_1000/945_Minimum_Increment_to_Make_Array_Unique.py
894
3.609375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/minimum-increment-to-make-array-unique/ # Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1. # Return the least number of moves to make every value in A unique. # Iterate over the sorted numbers. If a n...
2ef55af9838fbb71c144f53dc52779cf8806303f
jakehoare/leetcode
/python_1_to_1000/362_Design_Hit_Counter.py
2,142
3.5
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/design-hit-counter/ # Design a hit counter which counts the number of hits received in the past 5 minutes. # Each function accepts a timestamp parameter (in seconds granularity) and you may assume that calls are being made to # the system in chro...
0eca912eb359b3f343f06bda2874208395d5db17
jakehoare/leetcode
/python_1_to_1000/678_Valid_Parenthesis_String.py
1,629
4.15625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/valid-parenthesis-string/ # Given a string containing only three types of characters: '(', ')' and '*', write a function to check whether this # string is valid. We define the validity of a string by these rules: # 1. Any left parenthesis '(' mus...
3ac8d4fa3efc98ce5d472db5912411a25a35cdbd
jakehoare/leetcode
/python_1_to_1000/830_Positions_of_Large_Groups.py
1,062
3.75
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/positions-of-large-groups/ # In a string S of lowercase letters, these letters form consecutive groups of the same character. # For example, a string like S = "abbxxxxzyy" has the groups "a", "bb", "xxxx", "z" and "yy". # Call a group large if it...
d62ba0ce34c5caaebe4d6c74430700ae4678219e
jakehoare/leetcode
/python_1_to_1000/433_Minimum_Genetic_Mutation.py
2,349
3.953125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/minimum-genetic-mutation/ # A gene string can be represented by an 8-character long string, with choices from "A", "C", "G", "T". # Suppose we need to investigate about a mutation (mutation from "start" to "end"), where ONE mutation is defined as...
a09f42b9ead6ab7df24007685a3f8b22ec58464b
jakehoare/leetcode
/python_1_to_1000/028_Implement_strStr().py
857
3.8125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/implement-strstr/ # Implement strStr(). # Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. # For each pssible starting point in haystack, check characters match with needle and break if no...
a22ed8de59d23c7d402199a99177fd41655c9e06
jakehoare/leetcode
/python_1_to_1000/671_Second_Minimum_Node_In_a_Binary_Tree.py
1,461
3.828125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/second-minimum-node-in-a-binary-tree/ # Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree # has exactly two or zero sub-node. # If the node has two sub-nodes, then this node's valu...
0bf9cba8b0bfdc9a5657c4f81fb2a00d4474b074
jakehoare/leetcode
/python_1_to_1000/147_Insertion_Sort_List.py
1,268
4.125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/insertion-sort-list/ # Sort a linked list using insertion sort. # Maintain a sorted part of the list. For each next node, find its correct location by iterating along sorted section. # Time - O(n**2) # Space - O(1) # Definition for singly-link...
1dc27ed161eb49a5f4dd8f4bddb00b609a84d3b1
jakehoare/leetcode
/python_1_to_1000/521_Longest_Uncommon_Subsequence_I.py
1,299
3.984375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/longest-uncommon-subsequence-i/ # Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings. # The longest uncommon subsequence is defined as the longest subsequence of one of these strings and t...
ab862edcea80d9f4ffba4eea82ebdcdd89a882a7
jakehoare/leetcode
/python_1_to_1000/680_Valid_Palindrome_II.py
815
3.796875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/valid-palindrome-ii/ # Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. # Iterate over s from front and back. If chars do not match, check if the remainder after deleting either of the...
a36cae3b027e77785ed99b4d424f36ce79d81c01
jakehoare/leetcode
/python_1_to_1000/096_Unique_Binary_Search_Trees.py
1,275
3.671875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/unique-binary-search-trees/ # Given an integer n, count all structurally unique BST's (binary search trees) that store values 1...n. # Dynamic programming. Base case of 1 for n = 0 or 1. For each of n possible root nodes, multiply the # possib...
32d6072f051cf2728ff00459437b421c46a05ec8
jakehoare/leetcode
/python_1_to_1000/459_Repeated_Substring_Pattern.py
852
3.734375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/repeated-substring-pattern/ # Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of # the substring together. You may assume the given string consists of lowercase English letters onl...
b522a2fc861a9800bbe3a81cb0f6bbfa3ac63837
jakehoare/leetcode
/python_1001_to_2000/1175_Prime_Arrangements.py
1,010
3.5
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/prime-arrangements/ # Return the number of permutations of 1 to n so that prime numbers are at prime indices (1-indexed.) # Recall that an integer is prime if and only if it is greater than 1, # and cannot be written as a product of two positive ...
b30312465da4a1723218a765b5ad8e15a6765d2d
jakehoare/leetcode
/python_1_to_1000/334_Increasing_Triplet_Subsequence.py
800
3.96875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/increasing-triplet-subsequence/ # Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array. # Track the smallest num seen so far and the next_smallest. If we see a num larger than next_smallest, re...
c97039fa94d3b360340715c78d913ec639a81ff1
jakehoare/leetcode
/python_1_to_1000/946_Validate_Stack_Sequences.py
960
3.828125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/validate-stack-sequences/ # Given two sequences pushed and popped with distinct values, return true if and only if this could have been the # result of a sequence of push and pop operations on an initially empty stack. # Build the stack by itera...
024ac57caf8522d6b8dfacf8caa7b52ecfe76f60
jakehoare/leetcode
/python_1_to_1000/694_Number_of_Distinct_Islands.py
1,794
3.8125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/number-of-distinct-islands/ # Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected # 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water....
3c5bdf60fd31fd6b1b9c5d4cd0a1589757d1e825
jakehoare/leetcode
/python_1_to_1000/445_Add_Two_Numbers_II.py
1,529
3.90625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/add-two-numbers-ii/ # You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes # first and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. # ...
109189d2254ad130f2426f1f0274ddd8d7b49709
jakehoare/leetcode
/python_1001_to_2000/1055_Shortest_Way_to_Form_String.py
1,816
3.59375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/shortest-way-to-form-string/ # From any string, we can form a subsequence of that string by deleting some number of characters # (possibly no deletions). # Given two strings source and target, return the minimum number of subsequences of source s...
26ff67fe3ee1c7ecb086203409de9451af7298a9
jakehoare/leetcode
/python_1_to_1000/630_Course_Schedule_III.py
1,610
3.828125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/course-schedule-iii/ # There are n different online courses numbered from 1 to n. Each course has some duration(course length) t and closed # on dth day. A course should be taken continuously for t days and must be finished before or on the dth d...
e417b179065fe4b47f700f84be4474d6d5eeae78
jakehoare/leetcode
/python_1_to_1000/199_Binary_Tree_Right_Side_View.py
1,745
4.0625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/binary-tree-right-side-view/ # Given a binary tree, imagine yourself standing on the right side of it, # return the values of the nodes you can see ordered from top to bottom. # BFS layer by layer. Add to result last value found in a layer. # A...
8ba46ae776d6e5d3be2a115aa9a84be21ebdb808
jakehoare/leetcode
/python_1001_to_2000/1305_All_Elements_in_Two_Binary_Search_Trees.py
1,406
4
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/all-elements-in-two-binary-search-trees/ # Given two binary search trees root1 and root2. # Return a list containing all the integers from both trees sorted in ascending order. # Perform inorder traversals on each tree to get the node in ascendi...
c0dacaef40fe33d8b224eb9c9a593e66560662a7
jakehoare/leetcode
/python_1_to_1000/268_Missing_Number.py
473
3.671875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/missing-number/ # Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. # Subtract the sum from n*(n-1)/2 # Time - O(n) # Space - O(1) class Solution(object): def missingNumber...
b97633a8e1ed36fa60f1d6105f73e10e302fbe62
jakehoare/leetcode
/python_1_to_1000/339_Nested_List_Weighted_Sum.py
980
3.84375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/nested-list-weight-sum/ # Given a nested list of integers, return the sum of all integers in the list weighted by their depth. # Each element is either an integer, or a list -- whose elements may also be integers or other lists. # Iterate over ...
d11f329f9d9fc9926e42b58b5d3463375999a1c4
jakehoare/leetcode
/python_1001_to_2000/1162_As_Far_from_Land_as_Possible.py
2,051
3.734375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/as-far-from-land-as-possible/ # Given an N x N grid containing only values 0 and 1, where 0 represents water and 1 represents land, # find a water cell such that its distance to the nearest land cell is maximized and return the distance. # The di...
38368bacc930ee960cf03613aa9cc2a52d8f37ca
jakehoare/leetcode
/python_1_to_1000/111_Minimum_Depth_of_Binary_Tree.py
940
3.96875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/minimum-depth-of-binary-tree/ # Given a binary tree, find its minimum depth. # The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. # If either subtrees is not present, return 1 + min...
234b93477ad8928347e7d8953efe8ec1091e0eb6
jakehoare/leetcode
/python_1_to_1000/211_Add_and_Search_Word_-_Data_structure_design.py
1,558
3.984375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/add-and-search-word-data-structure-design/ # Design a data structure that supports the following two operations: # void addWord(word) # bool search(word) # search(word) can search a literal word or a regular expression string containing only lett...
fcc98f9c287db7afb21561e0513bb193941afb0b
jakehoare/leetcode
/python_1001_to_2000/1235_Maximum_Profit_in_Job_Scheduling.py
1,655
3.8125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/maximum-profit-in-job-scheduling/ # We have n jobs, where every job is scheduled to be done from startTime[i] to endTime[i], # obtaining a profit of profit[i]. # You're given the startTime , endTime and profit arrays, you need to output the maxim...
c7d95416131e6137c882824c363c571af7953d2a
jakehoare/leetcode
/python_1_to_1000/803_Bricks_Falling_When_Hit.py
2,235
4
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/bricks-falling-when-hit/ # We have a grid of 1s and 0s; the 1s in a cell represent bricks. A brick will not drop if and only if it is directly # connected to the top of the grid, or at least one of its (4-way) adjacent bricks will not drop. # We...
b59838f3a87b1ccaffa25ae7f6272cffcd69ca6b
jakehoare/leetcode
/python_1_to_1000/863_All_Nodes_Distance_K_in_Binary_Tree.py
2,382
4
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree/ # We are given a binary tree (with root node root), a target node, and an integer value K. # Return a list of the values of all nodes that have a distance K from the target node. # The answer can be returned i...
730dfeb2bb959814e897ba737ad795b6e1323a86
jakehoare/leetcode
/python_1_to_1000/501_Find_Mode_in_Binary_Search_Tree.py
2,068
3.671875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/find-mode-in-binary-search-tree/ # Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequent elements) in the BST. # Assume a BST is defined as follows: # The left subtree of a node contains only nodes with keys le...
eafed1a28b26c60325eace2cb2854790e3bd73c8
jakehoare/leetcode
/python_1_to_1000/764_Largest_Plus_Sign.py
2,354
3.609375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/largest-plus-sign/ # In a 2D grid from (0, 0) to (N-1, N-1), every cell contains a 1, except those cells in the given list mines which # are 0. What is the largest axis-aligned plus sign of 1s contained in the grid? # Return the order of the plus...
9a82ef6a51dca81e172dafdabf093730e57bce88
jakehoare/leetcode
/python_1_to_1000/087_Scramble_String.py
1,697
3.828125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/scramble-string/ # Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. # To scramble the string, we may choose any non-leaf node and swap its two children. # Given two strings s1 and...
ecba7ecd19be9b3771bea8afd3b7945657f16c16
jakehoare/leetcode
/python_1001_to_2000/1128_Number_of_Equivalent_Domino_Pairs.py
1,318
3.875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/number-of-equivalent-domino-pairs/ # Given a list of dominoes, dominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d] if and only if # either (a==c and b==d), or (a==d and b==c) - that is, one domino can be rotated to be equal to another domi...
54cdaafb398850dcf8c1b447acb722564b609090
jakehoare/leetcode
/python_1_to_1000/573_Squirrel_Simulation.py
1,701
4.03125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/squirrel-simulation/ # There's a tree, a squirrel, and several nuts. Positions are represented by the cells in a 2D grid. Your goal is to # find the minimal distance for the squirrel to collect all the nuts and put them under the tree one by one....
2cb1040042ca559bec03d55f5ecbc9be976ffcea
jakehoare/leetcode
/python_1_to_1000/010_Regular_Expression_Matching.py
1,598
3.640625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/regular-expression-matching/ # Implement regular expression matching with support for '.' and '*'. # '.' Matches any single character. # '*' Matches zero or more of the preceding element. # The matching should cover the entire input string (not p...
ddc8df49016992807eb5de2faa75e3d542a94f51
jakehoare/leetcode
/python_1001_to_2000/1250_Check_If_It_Is_a_Good_Array.py
1,127
3.59375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/check-if-it-is-a-good-array/ # Given an array nums of positive integers. # Your task is to select some subset of nums, multiply each element by an integer and add all these numbers. # The array is said to be good if you can obtain a sum of 1 from...
f4d2a42a70fcae45d9ad442b3420bc68a2ab16f7
jakehoare/leetcode
/python_1001_to_2000/1154_Day_of_the_Year.py
836
4
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/day-of-the-year/ # Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, # return the day number of the year. # Find the number of day in the whole months completed, assuming not a leap year. # Add 29th February if ...
21e4cab1dab67690f799947ef17f04d74b6c59a4
jakehoare/leetcode
/python_1_to_1000/517_Super_Washing_Machines.py
1,472
3.953125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/super-washing-machines/ # You have n super washing machines on a line. Initially, each washing machine has some dresses or is empty. # For each move, you could choose any m (1 ? m ? n) washing machines, and pass one dress of each washing machine ...
2266cc38bc22a3902f57ccb1d7b87efbe33b01ce
jakehoare/leetcode
/python_1001_to_2000/1039_Minimum_Score_Triangulation_of_Polygon.py
1,334
3.828125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/minimum-score-triangulation-of-polygon/ # Given N, consider a convex N-sided polygon with vertices labelled A[0], A[i], ..., A[N-1] in clockwise order. # Suppose you triangulate the polygon into N-2 triangles. # For each triangle, the value of th...
9f32235714433fc43fbc139e43bae944bce55159
jakehoare/leetcode
/python_1001_to_2000/1040_Moving_Stones_Until_Consecutive_II.py
2,508
4.0625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/moving-stones-until-consecutive-ii/ # On an infinite number line, the position of the i-th stone is given by stones[i]. # Call a stone an endpoint stone if it has the smallest or largest position. # Each turn, pick up an endpoint stone and move i...
c4d226fc5468c39fd38d9ae6339e6ec020793b8a
jakehoare/leetcode
/python_1_to_1000/560_Subarray_Sum_Equals_K.py
1,031
3.578125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/subarray-sum-equals-k/ # Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose # sum equals to k. # Store counts of prefix sums in dictionary. Iterate over array, updating running_sum and in...
07dd8a594084979d0687e987ff537132cfb44d53
jakehoare/leetcode
/python_1_to_1000/634_Find_the_Derangement_of_An_Array.py
1,353
3.6875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/find-the-derangement-of-an-array/ # In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no element appears # in its original position. # There's originally an array consisting of n integers from 1 to n...
189883e87e43ec3d09c912867cd8a095c8c2635b
jakehoare/leetcode
/python_1_to_1000/072_Edit_Distance.py
1,356
4.09375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/edit-distance/ # Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. # You have the following 3 operations permitted on a word (each 1 step): # a) Insert a character # b) Delete a character # c) R...
001c0cb06909efafe19e32de01d75718f9a5525a
jakehoare/leetcode
/python_1_to_1000/321_Create_Maximum_Number.py
2,967
3.546875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/create-maximum-number/ # Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of # length k <= m + n from digits of the two. The relative order of the digits from the same array must be preserved....
f470ec71995045194ef30bda58bfef30485c3a7b
jakehoare/leetcode
/python_1_to_1000/462_Minimum_Moves_to_Equal_Array_Elements_II.py
936
3.71875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/minimum-moves-to-equal-array-elements-ii/ # Given a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a # move is incrementing a selected element by 1 or decrementing a selected element by ...
28e4faf9d746b1b1928690ed38aa72ee2ce46129
jakehoare/leetcode
/python_1_to_1000/988_Smallest_String_Starting_From_Leaf.py
1,493
3.96875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/smallest-string-starting-from-leaf/ # Given the root of a binary tree, each node has a value from 0 to 25 representing the letters 'a' to 'z': # a value of 0 represents 'a', a value of 1 represents 'b', and so on. # Find the lexicographically sma...
d5d7f6aa80e45de328bd1bc229728aa043956be6
jakehoare/leetcode
/python_1001_to_2000/1101_The_Earliest_Moment_When_Everyone_Become_Friends.py
1,873
3.765625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends/ # In a social group, there are N people, with unique integer ids from 0 to N-1. # We have a list of logs, where each logs[i] = [timestamp, id_A, id_B] contains a non-negative integer timestamp, # ...
493f765e8d40f4211e10918e2f63e438f932dec7
jakehoare/leetcode
/python_1001_to_2000/1295_Find_Numbers_with_Even_Number_of_Digits.py
536
3.9375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/find-numbers-with-even-number-of-digits/ # Given an array nums of integers, return how many of them contain an even number of digits. # Convert each num to string and check if length is divisible by 2. # Time - O(n log k) for k numbers of max va...
b6470729a179c9146c8d8f7fd39757d24afab7a4
jakehoare/leetcode
/python_1_to_1000/676_Implement_Magic_Dictionary.py
2,608
3.90625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/implement-magic-dictionary/ # Implement a magic directory with buildDict, and search methods. # For the method buildDict, you'll be given a list of non-repetitive words to build a dictionary. # For the method search, you'll be given a word, and j...
29050104c9f722d43935c3f1ddcab047b861d1f7
jakehoare/leetcode
/python_1_to_1000/371_Sum_of_Two_Integers.py
909
3.59375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/sum-of-two-integers/ # Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. # Use mask to isolate 32 bits. Sum of 2 bits is the XOR. If both bits are set, carry to next bit. Repeat until no # more carry...
abfb2ef8386f8c1d781476eb51ee7603b1de40f2
jakehoare/leetcode
/python_1_to_1000/849_Maximize_Distance_to_Closest_Person.py
1,816
3.984375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/maximize-distance-to-closest-person/ # In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is empty. # There is at least one empty seat, and at least one person sitting. # Alex wants to sit in the seat su...
052eacf4b9b260e9f144446f172b81216946933c
jakehoare/leetcode
/python_1001_to_2000/1213_Intersection_of_Three_Sorted_Arrays.py
842
4.15625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/intersection-of-three-sorted-arrays/ # Given three integer arrays arr1, arr2 and arr3 sorted in strictly increasing order, # return a sorted array of only the integers that appeared in all three arrays. # Count the frequency across all arrays. #...
363292d9074408a12c4f97e1948604aba2c244f2
jakehoare/leetcode
/python_1_to_1000/609_Find_Duplicate_File_in_System.py
1,937
3.765625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/find-duplicate-file-in-system/ # Given a list of directory info including directory path, and all the files with contents in this directory, you # need to find out all the groups of duplicate files in the file system in terms of their paths. # A ...
3cc5b066a35d7b9135c9fe7cf8a98fde78d4471e
jakehoare/leetcode
/python_1_to_1000/1000_Minimum_Cost_to_Merge_Stones.py
1,714
3.75
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/minimum-cost-to-merge-stones/ # There are N piles of stones arranged in a row. The i-th pile has stones[i] stones. # A move consists of merging exactly K consecutive piles into one pile, and the cost of this move is equal to the # total number o...
eba7ef140c8e1daea8a3363a0ffbc3324f253000
jakehoare/leetcode
/countdown.py
3,039
3.625
4
from collections import deque # Examples: # print(CountdownSolver().countdownBFS([6, 3, 100, 75, 50, 25], 955)) # print(CountdownSolver().countdownBFS([2, 5, 7, 8, 9, 75], 569)) class CountdownSolver: def countdownBFS(self, input_nums, target): best, best_ops = 0, [] # closest to target, the list of...
8a5001d33c01aed32a54e717802e99cedfbfcfc5
jakehoare/leetcode
/python_1001_to_2000/1273_Delete_Tree_Nodes.py
1,677
3.734375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/delete-tree-nodes/ # A tree rooted at node 0 is given as follows: # The number of nodes is nodes; # The value of the i-th node is value[i]; # The parent of the i-th node is parent[i]. # Remove every subtree whose sum of values of nodes is zero. #...
7c4cd5f280f413a5c9eb8442b7c6910999fcf79f
jakehoare/leetcode
/python_1_to_1000/650_2_Keys_Keyboard.py
1,271
3.6875
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/2-keys-keyboard/ # Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step: # Copy All: You can copy all the characters present on the notepad (partial copy is not allowed). # Paste...
e03b799faec64b280cbd2a81be2562ff0bfcaa3d
jakehoare/leetcode
/python_1_to_1000/759_Employee_Free_Time.py
2,186
3.734375
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/employee-free-time/ # We are given a list schedule of employees, which represents the working time for each employee. # Each employee has a list of non-overlapping Intervals, and these intervals are in sorted order. # Return the list of finite in...
1c6284e36e312ce42ee7fc7aa7a19f6e191e6b11
jakehoare/leetcode
/python_1_to_1000/545_Boundary_of_Binary_Tree.py
2,267
4.125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/boundary-of-binary-tree/ # Given a binary tree, return the values of its boundary in anti-clockwise direction starting from root. Boundary # includes left boundary, leaves, and right boundary in order without duplicate nodes. # Left boundary is d...
3eb3452c15ac92b6919fdf8a084b59062b9e2f4f
jakehoare/leetcode
/python_1_to_1000/345_Reverse_Vowels_of_a_String.py
854
3.8125
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/reverse-vowels-of-a-string/ # Write a function that takes a string as input and reverse only the vowels of a string. # Find list of indices of vowels in s. Swap vowel at first index with vowel at last index, until meeting in middle # of list of ...
30ff3d4d8f4a67a2520ada5f65fbba374bcbc995
jakehoare/leetcode
/python_1_to_1000/101_Symmetric_Tree.py
1,208
4.15625
4
_author_ = 'jake' _project_ = 'leetcode' # https://leetcode.com/problems/symmetric-tree/ # Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). # Check if left and right subtrees are both present or not, then if root values are equal. Then recurse on their # subtrees being m...