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
5cc255f87d0a6877d8495ba284d2afe16afdb118
akimi-yano/algorithm-practice
/lc/1781.SumOfBeautyOfAllSubstrings.py
1,487
3.953125
4
# 1781. Sum of Beauty of All Substrings # Medium # 41 # 31 # Add to List # Share # The beauty of a string is the difference in frequencies between the most frequent and least frequent characters. # For example, the beauty of "abaacc" is 3 - 1 = 2. # Given a string s, return the sum of beauty of all of its substrin...
c44b11df4ff6aecd21947fa79632a0991ed5fa0e
akimi-yano/algorithm-practice
/lc/86.PartitionList.py
1,413
3.984375
4
# 86. Partition List # Medium # 2146 # 393 # Add to List # Share # Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. # You should preserve the original relative order of the nodes in each of the two partitions. # Example 1:...
2b0f70093994c026f521f5936967fcc887c74444
akimi-yano/algorithm-practice
/lc/1870.MinimumSpeedToArriveOnTime.py
2,783
4.21875
4
# 1870. Minimum Speed to Arrive on Time # Medium # 152 # 49 # Add to List # Share # You are given a floating-point number hour, representing the amount of time you have to reach the office. To commute to the office, you must take n trains in sequential order. You are also given an integer array dist of length n, wh...
683bd029ec511e1c2868af454303d95065e93c23
akimi-yano/algorithm-practice
/lc/438.FindAllAnagramsInAString.py
1,687
4.25
4
# 438. Find All Anagrams in a String # Medium # 6188 # 235 # Add to List # Share # Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order. # An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typi...
fd455d49e42e687c8defe5ccb170663167cbf5ee
akimi-yano/algorithm-practice
/warmUpOC/sorting-bucketSort.py
1,422
3.578125
4
# Sorting - Bucket Sort #### Prompt Given an unsorted array of numbers which are randomly distributed across the a range, sort the numbers using bucket sort. Input: - {Array} - floats - {Float} - minimum of range (inclusive) - {Float} - maximum of range (exclusive) Output: - {Array} #### Examples Input: ...
de70bf83a103b510f08fa575a4bca22a726e9248
akimi-yano/algorithm-practice
/lc/review_458.PoorPigs.py
1,729
3.703125
4
# 458. Poor Pigs # Hard # 847 # 1715 # Add to List # Share # There are buckets buckets of liquid, where exactly one of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have minutesToTest minute...
9ebb33958889c5749fffaaebe3ed402b18b7ddaa
akimi-yano/algorithm-practice
/lc/review_413.ArithmeticSlices.py
1,311
3.546875
4
# 413. Arithmetic Slices # Medium # 3037 # 233 # Add to List # Share # An integer array is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same. # For example, [1,3,5,7,9], [7,7,7,7], and [3,-1,-5,-9] are arithmetic sequences. # Given an...
1d0e8f34c91ec213dcba235479113a0d53d6c6da
akimi-yano/algorithm-practice
/lc/1007.MinimumDominoRotationsForEqu.py
4,490
4.03125
4
# 1007. Minimum Domino Rotations For Equal Row # Medium # 997 # 178 # Add to List # Share # In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the ith domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.) # We may rotate the ith domino, so that A[i] and ...
065949741b9282c9dad7a218be8ef61e7dc89f74
akimi-yano/algorithm-practice
/lc/61.RotateList.py
4,585
4.1875
4
# 61. Rotate List # Medium # 1628 # 1063 # Add to List # Share # Given a linked list, rotate the list to the right by k places, where k is non-negative. # Example 1: # Input: 1->2->3->4->5->NULL, k = 2 # Output: 4->5->1->2->3->NULL # Explanation: # rotate 1 steps to the right: 5->1->2->3->4->NULL # rotate 2 steps...
992978156135487a789367fa7736a765660411c1
akimi-yano/algorithm-practice
/lc/1702.MaximumBinaryStringAfterChan.py
5,347
4.15625
4
# 1702. Maximum Binary String After Change # Medium # 62 # 6 # Add to List # Share # You are given a binary string binary consisting of only 0's or 1's. You can apply each of the following operations any number of times: # Operation 1: If the number contains the substring "00", you can replace it with "10". # For ...
c6c861d7eb60c6b665de80aed655cb8f33dc773d
akimi-yano/algorithm-practice
/lc/299.BullsAndCows.py
3,231
4.09375
4
# 299. Bulls and Cows # Easy # 746 # 902 # Add to List # Share # You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint that indicates how many digits in said guess match you...
d619f15e9e4ff2ba8d352390606d572a8a2506b7
akimi-yano/algorithm-practice
/lc/1659.MaximizeGridHappiness.py
5,132
3.859375
4
# 1659. Maximize Grid Happiness # Hard # 54 # 26 # Add to List # Share # You are given four integers, m, n, introvertsCount, and extrovertsCount. You have an m x n grid, and there are two types of people: introverts and extroverts. There are introvertsCount introverts and extrovertsCount extroverts. # You should d...
ec52fb78ea2b91eaa9e2dc171c5ecc82087b51b0
akimi-yano/algorithm-practice
/interviewOCweekly/week1_basic_recursion_dp/PlusOne.py
607
3.671875
4
# 201 - Plus One # Given a positive integer represented by an array of digits, add one that number. # ``` # Input: Array of integers # Output: Array of integers # ``` # # Example # ``` # Input: [1,2,3] => Output: [1,2,4] # Input: [1, 9] => Output: [2,0] # Input: [9,9,9] => Output: [1,0,0,0] # ``` # # Constrai...
828879ec7bbfeb56f44b558e961fdc4017d59c7f
akimi-yano/algorithm-practice
/lc/1814.CountNicePairsInAnArray.py
3,029
3.609375
4
# 1814. Count Nice Pairs in an Array # Medium # 103 # 11 # Add to List # Share # You are given an array nums that consists of non-negative integers. Let us define rev(x) as the reverse of the non-negative integer x. For example, rev(123) = 321, and rev(120) = 21. A pair of indices (i, j) is nice if it satisfies all...
3fb35bedc73c2b00e0f6bb6919c35faf39db4d2c
akimi-yano/algorithm-practice
/lc/1010.PairsOfSongsWithTotalDurati.py
1,959
3.640625
4
# 1010. Pairs of Songs With Total Durations Divisible by 60 # Medium # 923 # 68 # Add to List # Share # You are given a list of songs where the ith song has a duration of time[i] seconds. # Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the numbe...
37f69158f54c60244fff0b3979e6d28c9e8b7020
akimi-yano/algorithm-practice
/lc/600.Non-negativeIntegersWithoutCon.py
2,111
3.6875
4
# 600. Non-negative Integers without Consecutive Ones # Hard # 828 # 96 # Add to List # Share # Given a positive integer n, return the number of the integers in the range [0, n] whose binary representations do not contain consecutive ones. # Example 1: # Input: n = 5 # Output: 5 # Explanation: # Here are the n...
786e6a2c60534a7abe99179ebe7d5349e8dc0574
akimi-yano/algorithm-practice
/lc/309.BestTimeToBuyAndSellStockW.py
2,181
3.734375
4
# 309. Best Time to Buy and Sell Stock with Cooldown # Medium # 4351 # 143 # Add to List # Share # You are given an array prices where prices[i] is the price of a given stock on the ith day. # Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sell one sha...
f2f2bb7518aeddb12ce100925b711916f87c845e
akimi-yano/algorithm-practice
/lc/review_540.SingleElementInASortedArray.py
1,515
3.6875
4
# 540. Single Element in a Sorted Array # Medium # 3653 # 95 # Add to List # Share # You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. # Return the single element that appears only once. # Your solution must run i...
054339316bdf7eb88cf5950813d0793841ced775
akimi-yano/algorithm-practice
/lc/review_162.FindPeakElement.py
2,220
3.890625
4
# 162. Find Peak Element # Medium # 3446 # 2866 # Add to List # Share # A peak element is an element that is strictly greater than its neighbors. # Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks. # You may imagine ...
1f589df19ac79258876631a2ad82378643378794
akimi-yano/algorithm-practice
/lc/1850.MinimumAdjacentSwapsToReach.py
2,835
3.8125
4
# 1850. Minimum Adjacent Swaps to Reach the Kth Smallest Number # Medium # 35 # 11 # Add to List # Share # You are given a string num, representing a large integer, and an integer k. # We call some integer wonderful if it is a permutation of the digits in num and is greater in value than num. There can be many won...
8fda379ee80ceca39c964fcbeb1249588b00eecc
akimi-yano/algorithm-practice
/targetPracticeOC/matrix.py
5,161
4.1875
4
# # Target Practice 12 - Matrices # # # Problem 1: Robot Paths # # Prompt: Given a matrix of zeroes, determine how many unique paths exist # from the top left corner to the bottom right corner # # Input: An Array of Array of Integers (matrix) # Output: Integer # # Example: matrix = [[0,0,0,0], # ...
bddc63619cdf56c8c702c93ff94cc44599a19db4
akimi-yano/algorithm-practice
/lc/978.LongestTurbulentSubarray.py
2,816
3.515625
4
# 978. Longest Turbulent Subarray # Medium # 964 # 154 # Add to List # Share # Given an integer array arr, return the length of a maximum size turbulent subarray of arr. # A subarray is turbulent if the comparison sign flips between each adjacent pair of elements in the subarray. # More formally, a subarray [arr[...
def7f4508f1f341cbba30b8574336ba4fb8b4d8c
akimi-yano/algorithm-practice
/lc/205.IsomorphicStrings.py
1,365
3.96875
4
# 205. Isomorphic Strings # Easy # 2419 # 512 # Add to List # Share # Given two strings s and t, determine if they are isomorphic. # Two strings s and t are isomorphic if the characters in s can be replaced to get t. # All occurrences of a character must be replaced with another character while preserving the ord...
c2cfe9c12407f046dbc9c48b3af8e7555252f024
akimi-yano/algorithm-practice
/oc/ropeProblem.py
1,614
4
4
# /*Given n ropes of different lengths represented by an array of integers, # connect them all into a single rope in a way that minimizes the cost of connecting # them. # The cost of connecting two ropes is equal to sum of their lengths. We want to # minimize the cost of connecting all the ropes. # Input: ...
d82ee902dd1d6face17043b26d25dfadcc770e51
akimi-yano/algorithm-practice
/cc/06192020.py
9,338
4.28125
4
# It consists of 2 questions that we ask that you complete in Python. # There is a 76 minute time limit, but expect that many people can finish in significantly less time. # Correctness is important, but equally important is the clarity and elegance of your code. # We will be evaluating your solutions with both of ...
bc920ae88669d89cf800654010d1e24630b96bf8
akimi-yano/algorithm-practice
/lc/1437.CheckIfAll1'sAreAtLeastLe.py
1,188
3.75
4
# 1437. Check If All 1's Are at Least Length K Places Away # Easy # 208 # 166 # Add to List # Share # Given an array nums of 0s and 1s and an integer k, return True if all 1's are at least k places away from each other, otherwise return False. # Example 1: # Input: nums = [1,0,0,0,1,0,0,1], k = 2 # Output: t...
3722cfad9945736dc7f137970effb5ad55246ac9
akimi-yano/algorithm-practice
/lc/895.MaximumFrequencyStack.py
2,672
3.625
4
# 895. Maximum Frequency Stack # Hard # 1587 # 34 # Add to List # Share # Implement FreqStack, a class which simulates the operation of a stack-like data structure. # FreqStack has two functions: # push(int x), which pushes an integer x onto the stack. # pop(), which removes and returns the most frequent element ...
25a0f465b5afc576a05e1a34c32932c9f96a2ec9
akimi-yano/algorithm-practice
/lc/review_856.ScoreOfParentheses.py
1,578
3.734375
4
# 856. Score of Parentheses # Medium # 3273 # 97 # Add to List # Share # Given a balanced parentheses string s, return the score of the string. # The score of a balanced parentheses string is based on the following rule: # "()" has score 1. # AB has score A + B, where A and B are balanced parentheses strings. # (...
9f65b50ed653e9109425ea2f38f26e0f191255ac
akimi-yano/algorithm-practice
/lc/1705.MaximumNumberOfEatenApples.py
3,132
3.734375
4
# 1705. Maximum Number of Eaten Apples # Medium # 45 # 58 # Add to List # Share # There is a special kind of apple tree that grows apples every day for n days. On the ith day, the tree grows apples[i] apples that will rot after days[i] days, that is on day i + days[i] the apples will be rotten and cannot be eaten. ...
00af46653b4b814c0a99ef8e7e148333ece75bc3
akimi-yano/algorithm-practice
/lc/231.PowerOfTwo.py
1,149
4
4
# 231. Power of Two # Easy # 2235 # 260 # Add to List # Share # Given an integer n, return true if it is a power of two. Otherwise, return false. # An integer n is a power of two, if there exists an integer x such that n == 2x. # Example 1: # Input: n = 1 # Output: true # Explanation: 20 = 1 # Example 2: # I...
beda2c8b84bfa3be65e93edacf33c71c524f2718
akimi-yano/algorithm-practice
/lc/isTreeSymmetric.py
2,043
4.34375
4
# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None # 101. Symmetric Tree # Easy # Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). # For example, this binary tree...
a009f272dcc2c434808405afed6a2e4152a30ec5
akimi-yano/algorithm-practice
/lc/review_1048.LongestStringChain.py
2,244
3.828125
4
# 1048. Longest String Chain # Medium # 3540 # 167 # Add to List # Share # You are given an array of words where each word consists of lowercase English letters. # wordA is a predecessor of wordB if and only if we can insert exactly one letter anywhere in wordA without changing the order of the other characters to...
430cb787d491a842500e24d7563fac8b798341bc
akimi-yano/algorithm-practice
/lc/1751.MaximumNumberOfEventsThatCa.py
2,399
3.78125
4
# 1751. Maximum Number of Events That Can Be Attended II # Hard # 87 # 2 # Add to List # Share # You are given an array of events where events[i] = [startDayi, endDayi, valuei]. The ith event starts at startDayi and ends at endDayi, and if you attend this event, you will receive a value of valuei. You are also give...
863959c095a9a4713ab0e33a08e08faa7bba8b63
akimi-yano/algorithm-practice
/lc/1568.MinimumNumberOfDaysToDiscon.py
3,811
3.796875
4
# 1568. Minimum Number of Days to Disconnect Island # Given a 2D grid consisting of 1s (land) and 0s (water). An island is a maximal 4-directionally (horizontal or vertical) connected group of 1s. # The grid is said to be connected if we have exactly one island, otherwise is said disconnected. # In one day, we are ...
c6854a19ee1263bee267aa18ba06920d15b5469c
akimi-yano/algorithm-practice
/grokkingDP/1.2_EqualSubsetSumPartition.py
5,735
4.09375
4
# 1.2 - Equal Subset Sum Partition # Problem Statement # # Given a set of positive numbers, find if we can partition it into two subsets such that the sum of elements in both the subsets is equal. # Example 1: # # Input: {1, 2, 3, 4} # Output: True # Explanation: The given set can be partitioned into two subsets with ...
0f4bfcbc1f59afbb95c2a2d112b72e1f34c798d0
akimi-yano/algorithm-practice
/lc/111.MinimumDepthOfBinaryTree.py
2,149
4.125
4
# 111. Minimum Depth of Binary Tree # Easy # 1823 # 759 # Add to List # Share # 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. # Note: A leaf is a node with no children. # Example 1: # Input: r...
8203b682b0b5c472898db17c59001ad862a9d983
akimi-yano/algorithm-practice
/lc/review_34.FindFirstAndLastPositionOfEl.py
2,272
3.90625
4
# 34. Find First and Last Position of Element in Sorted Array # Medium # 5510 # 209 # Add to List # Share # Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. # If target is not found in the array, return [-1, -1]. # Follow up: Could you write...
0245148394ff89d0de2d082a8a553c436ae91967
akimi-yano/algorithm-practice
/lc/967.NumbersWithSameConsecutiveDif.py
2,904
3.578125
4
# 967. Numbers With Same Consecutive Differences # Return all non-negative integers of length N such that the absolute difference between every two consecutive digits is K. # Note that every number in the answer must not have leading zeros except for the number 0 itself. For example, 01 has one leading zero and is in...
99807557a16613d1e9a52417868f0c92aabaf9f8
akimi-yano/algorithm-practice
/lc/1832.CheckIfTheSentenceIsPangram.py
945
3.96875
4
# 1832. Check if the Sentence Is Pangram # Easy # 66 # 0 # Add to List # Share # A pangram is a sentence where every letter of the English alphabet appears at least once. # Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise. # Example 1: ...
06b0a9a908d12f781214fc070e8cb207f9046602
akimi-yano/algorithm-practice
/lc/445.AddTwoNumbersII.py
4,985
4.03125
4
# 445. Add Two Numbers II # Medium # 1821 # 177 # Add to List # Share # 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. # You may assume the tw...
650a80cc16838db3dfcfb8ccf54326128e68c43d
akimi-yano/algorithm-practice
/tutoring/mockP/mockInterview5.py
3,675
3.890625
4
""" [ [7,4,1], [8,5,2], [9,6,3] ] """ arr = [ [1,2,3], [4,5,6], [7,8,9] ] arr = [ [1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16] ] # def rotate(array): # # switching row and columns # for row in range(len(array)): # for col in range(row,len(array[row])): # array[row][col]...
1db57cbc2fc38f82331e206da396ebeafd78440c
akimi-yano/algorithm-practice
/lc2/explore_top_interview_questions_easy/PlusOne.py
1,611
3.96875
4
''' Plus One You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's. Increment the large integer by one and...
152fd4f0a8b45faa2164cf3507b3374360467c4e
akimi-yano/algorithm-practice
/lc/148.SortList.py
2,169
4.03125
4
# 148. Sort List # Sort a linked list in O(n log n) time using constant space complexity. # Example 1: # Input: 4->2->1->3 # Output: 1->2->3->4 # Example 2: # Input: -1->5->3->4->0 # Output: -1->0->3->4->5 # This solution works but it is not constant space - but I like it - using merge sort # Definition for sin...
a770ed5446cb22606122f0d55488d58aff374679
akimi-yano/algorithm-practice
/examOC/examWeek1.py
2,868
4.15625
4
# Week1 Exam # Complete the 'mergeArrays' function below. # # The function is expected to return an INTEGER_ARRAY. # The function accepts following parameters: # 1. INTEGER_ARRAY a # 2. INTEGER_ARRAY b # merge two sorted arrays def mergeArrays(a, b): ans = [] i = 0 k = 0 while len(a)>i and len(b...
754bbb2d29c2e2bcb26eb382a95d6cf46fb36cb9
akimi-yano/algorithm-practice
/lc/review_1492.TheKthFactorOfN.py
2,576
3.96875
4
# 1492. The kth Factor of n # Medium # 210 # 89 # Add to List # Share # 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...
e96e83296e9676196104945f14c6463288ddc14e
akimi-yano/algorithm-practice
/lc/922.SortArrayByParityII.py
2,088
4.0625
4
# 922. Sort Array By Parity II # Easy # 1418 # 65 # Add to List # Share # Given an array of integers nums, half of the integers in nums are odd, and the other half are even. # Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even. # Return any answer array that satisfie...
ad148fc2f71439ad3773f6220a0e00e2223e4473
akimi-yano/algorithm-practice
/lc/436.FindRightInterval.py
4,314
3.96875
4
# 436. Find Right Interval # Given a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than or equal to the end point of the interval i, which can be called that j is on the "right" of i. # For any interval i, you need to store the minimum interval j's index...
4a10387c4cf21d44b45f7ae3dd7361a70f194567
akimi-yano/algorithm-practice
/lc/1544.MakeTheStringGreat.py
2,385
3.96875
4
# 1544. Make The String Great # Easy # 49 # 12 # Add to List # Share # Given a string s of lower and upper case English letters. # A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where: # 0 <= i <= s.length - 2 # s[i] is a lower-case letter and s[i + 1] is the same letter bu...
442f8ae5f2b285229bdbcfce757468c4e8f08871
akimi-yano/algorithm-practice
/lc/review_56.MergeIntervals.py
2,060
3.84375
4
# 56. Merge Intervals # Medium # 5640 # 336 # Add to List # Share # Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input. # Example 1: # Input: intervals = [[1,3],[2,6],[8...
c011f9b6ff0b95a20cbaa9dae1672bcba090f490
akimi-yano/algorithm-practice
/interviewOCweekly/week2_slidingWindow_linkedList_binaryTree_graph/consecSubArrSum.py
1,306
3.71875
4
# # 222 - Consecutive Subarray Sum # Given an array of positive integers and a target value, return true if there is a subarray of consecutive elements that sum up to this target value. # ``` # Input: Array of integers, target value # Output: Boolean # ``` # # Example # ``` # Input: [6,12,1,7,5,2,3], 14 => Ou...
ef60f4bd231f462a4f367d7a05f69ca238a53ddb
akimi-yano/algorithm-practice
/lc/946.ValidateStackSequences.py
1,270
3.609375
4
# 946. Validate Stack Sequences # Medium # 1547 # 35 # Add to List # Share # 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. # Example 1: # Input: pushed = [1,2,3,4,5], p...
2ca23aa531575e307388a100b1c2bd212a91de6c
akimi-yano/algorithm-practice
/lc/if_array_pairs_are_divisible_by_k.py
2,119
3.578125
4
# check-if-array-pairs-are-divisible-by-k # [Check If Array Pairs Are Divisible by k https://leetcode.com/contest/weekly-contest-195/problems/check-if-array-pairs-are-divisible-by-k/] # mod k の値のみに注目し、基本的には i と k-i の個数が等しいかを check。i = 0のときと、k が偶数のときは i = k/2 のときは別に処理しないといけない。 # this doesnt work - look below solution...
33d202be5506f467ebbbb6ed9f86bb6362af9c30
akimi-yano/algorithm-practice
/lc/224.BasicCalculator.py
3,685
4.125
4
# 224. Basic Calculator # Hard # 2777 # 249 # Add to List # Share # Given a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation. # Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, s...
94d942c6bc11ceb1a8919f193e31a186f1a90658
akimi-yano/algorithm-practice
/lc/154.FindMinimumInRotatedSortedAr.py
2,593
4.15625
4
# 154. Find Minimum in Rotated Sorted Array II # Hard # 2147 # 315 # Add to List # Share # Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,4,4,5,6,7] might become: # [4,5,6,7,0,1,4] if it was rotated 4 times. # [0,1,4,4,5,6,7] if it was ro...
c079ed37d88ec13c604fc1cbd82e8ab2b9ac2d11
akimi-yano/algorithm-practice
/lc/203.RemoveLinkedListElements.py
1,188
3.9375
4
# 203. Remove Linked List Elements # Easy # 3761 # 140 # Add to List # Share # Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head. # Example 1: # Input: head = [1,2,6,3,4,5,6], val = 6 # Output: [1,2,3,4,5] # Example 2:...
dfafe4bfe8bbe45bb4378b281523df87f4ba0af7
akimi-yano/algorithm-practice
/lc/115.DistinctSubsequences.py
1,385
3.65625
4
# 115. Distinct Subsequences # Hard # 2651 # 115 # Add to List # Share # Given two strings s and t, return the number of distinct subsequences of s which equals t. # A string's subsequence is a new string formed from the original string by deleting some (can be none) of the characters without disturbing the remain...
0cc0cb437850502b3a0292c7fdf0f641bbbd89e9
akimi-yano/algorithm-practice
/lc/165.CompareVersionNumbers.py
2,780
3.9375
4
# 165. Compare Version Numbers # Medium # 592 # 1540 # Add to List # Share # Compare two version numbers version1 and version2. # If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0. # You may assume that the version strings are non-empty and contain only digits and the . character...
d2ddba38d4e3167399a5ed20667e497f647f4f42
akimi-yano/algorithm-practice
/lc/1561.MaximumNumberOfCoinsYouCan.py
1,839
3.90625
4
# 1561. Maximum Number of Coins You Can Get # There are 3n piles of coins of varying size, you and your friends will take piles of coins as follows: # In each step, you will choose any 3 piles of coins (not necessarily consecutive). # Of your choice, Alice will pick the pile with the maximum number of coins. # You wi...
bf66da35c67d51fc5faf9682bddd09fe451cf356
akimi-yano/algorithm-practice
/mocks/ms/ms_mock1.py
1,206
3.984375
4
''' https://codeinterview.io/playback/POYYURIJTT#?t=1609 implement color fill / paint fill input: x, y - where - integers canvas - what - 2D color -what with - Color object {} fill() output: no output - modify in place name: fill() input output / O - fill background - fill within the shape ''' def trav...
e53da9ade4122737f130494f855ee5d327404a75
akimi-yano/algorithm-practice
/lc/1288.RemoveCoveredIntervals.py
3,323
3.78125
4
# 1288. Remove Covered Intervals # Medium # 354 # 18 # Add to List # Share # Given a list of intervals, remove all intervals that are covered by another interval in the list. # Interval [a,b) is covered by interval [c,d) if and only if c <= a and b <= d. # After doing so, return the number of remaining intervals....
c311450a3cab7ffa7397a082cae3f42a194232ef
akimi-yano/algorithm-practice
/lc/review2_1091.ShortestPathInBinaryMatrix.py
1,718
3.828125
4
# 1091. Shortest Path in Binary Matrix # Medium # 2754 # 132 # Add to List # Share # Given an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1. # A clear path in a binary matrix is a path from the top-left cell (i.e., (0, 0)) to the bottom-r...
f71eec9135813d3f65ff98600ed1c5db1bb5fe9c
akimi-yano/algorithm-practice
/lc/78.Subsets.py
883
3.59375
4
# 78. Subsets # Medium # 8514 # 137 # Add to List # Share # Given an integer array nums of unique elements, 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,3] # Output: [[],[1],[2],[1,2],[3]...
47dc462b6659e9cfbba52817c72617436e46e30d
akimi-yano/algorithm-practice
/lc/739.DailyTemperatures.py
1,768
4.09375
4
# 739. Daily Temperatures # Medium # 5516 # 143 # Add to List # Share # Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this...
448467cb0445f9e81c67e1c29ff29d4545a47b88
akimi-yano/algorithm-practice
/lc/UniquePaths.py
2,518
4.40625
4
# latice path unique path problems are different problems ! # difference : # lattice path - counting the edges # robot unique path - counting the boxes (so -1) # also for lattice path, # instead of doing this ---- # if m == 0 and n == 0: # return 1 # elif m<0 or n<0: # return 0 # you ...
e73ee24f6c0de9f4f3746b2836c73d4797887919
akimi-yano/algorithm-practice
/lc/1626.BestTeamWithNoConflicts.py
3,563
3.90625
4
# 1626. Best Team With No Conflicts # Medium # 83 # 4 # Add to List # Share # You are the manager of a basketball team. For the upcoming tournament, you want to choose the team with the highest overall score. The score of the team is the sum of scores of all the players in the team. # However, the basketball team ...
0f34f59efb1770266af215cf5344ee2dca1a6d74
akimi-yano/algorithm-practice
/lc/SelfBalancedBST.py
1,959
3.859375
4
# 108. Convert Sorted Array to Binary Search Tree # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right #solution1: # class Solution: # def __init__(self): # self.root ...
538de6858f4e272715305553aab839791e55db0d
akimi-yano/algorithm-practice
/tutoring/mockP/mockInterview9.py
1,083
4.03125
4
# 539. Minimum Time Difference # Given a list of 24-hour clock time points in "Hour:Minutes" format, # find the minimum minutes difference between any two time points in the list. # Example 1: # Input: ["23:59","00:00"] # Output: 1 # Note: # The number of time points in the given list is at least 2 # and won't exce...
1e8ec6f45edee4fc735a4c0288ec113cf7fcfb62
akimi-yano/algorithm-practice
/mocks/io/mock1.py
1,788
3.609375
4
# # Your previous Plain Text content is preserved below: # # /* # 2 params: list of ints, distance # group([1, 2, 3, 10, 22, 25, 50, 100, 101, 150], 10) -> [[1, 2, 3, 10], [22, 25], [100, 101]] # group([1, 2, 3, 10, 15, 22, 25, 50, 100, 101, 150], 10) -> [[1, 2, 3, 10, 15, 22, 25], [100, 101]] # group([1, 2, 3, 10, ...
90b26743ba94c1a1bce39ad04966dbe47ca7ec69
akimi-yano/algorithm-practice
/oc/bfs_graph_traversal.py
530
3.734375
4
graph = { 1: [2, 3, 4], 2: [5], 3: [], 4: [6, 7], 5: [], 6: [3], 7: [] } start = 1 def graphBFS(graph, start): queue = [start] visited = set([]) # enqueue() -> append() # dequeue() -> pop(0) while len(queue) > 0: current = queue.pop(0) visited.add(current...
de00912bf950e57ec1e451fbbb74335981fe6d29
akimi-yano/algorithm-practice
/lc/91.DecodeWays.py
1,214
3.796875
4
# 91. Decode Ways # 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. # Example 1: # Input: "12" # Output: 2 # Explanation: It coul...
d78c0e6fad5cab2a6320ff74f7efa90b2dfcd319
akimi-yano/algorithm-practice
/lc/review_19.RemoveNthNodeFromEndOfList.py
1,183
3.984375
4
# 19. Remove Nth Node From End of List # Medium # 12712 # 544 # Add to List # Share # Given the head of a linked list, remove the nth node from the end of the list and return its head. # Example 1: # Input: head = [1,2,3,4,5], n = 2 # Output: [1,2,3,5] # Example 2: # Input: head = [1], n = 1 # Output: [] # E...
2b4f5986e1f2533b0ee4ff3f7483a512e43d546a
akimi-yano/algorithm-practice
/lc/442.FindAllDuplicatesInAnArray.py
1,366
3.953125
4
# 442. Find All Duplicates in an Array # Medium # 4505 # 209 # Add to List # Share # Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears once or twice, return an array of all the integers that appears twice. # You must write an algorithm that runs...
50a469f7eb3692d4e9b1f4cfd7c494b07aa80d4a
akimi-yano/algorithm-practice
/lc/289.GameOfLife.py
4,528
3.984375
4
# 289. Game of Life # According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970." # Given a board with m by n cells, each cell has an initial state live (1) or dead (0). Each cell interacts with its eight...
bbff68a7bd8d8ca98049fb14e5b672995625181c
akimi-yano/algorithm-practice
/oc/trappingRainWater.py
11,455
4.125
4
# 406 - Trapping Rain Water # Given an array arr[] of N non-negative integers representing height of # blocks at index i as Ai where the width of each block is 1. # Compute how much water can be trapped in between blocks after raining. # ex) # Input: [3, 0, 2, 0, 4] # Output: 7 # Basic Insight: # An elemen...
dae79ac239b94d4f174d3293cea22c395e06a03e
akimi-yano/algorithm-practice
/lc/680.ValidPalindromeII.py
3,654
3.84375
4
# 680. Valid Palindrome II # Easy # 1936 # 124 # Add to List # Share # Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. # Example 1: # Input: "aba" # Output: True # Example 2: # Input: "abca" # Output: True # Explanation: You could delete the character '...
a5e9b02600b828e3aa39867136c0e4c4685962bd
akimi-yano/algorithm-practice
/lc/1305.AllElementsInTwoBinarySearc.py
2,005
3.921875
4
# 1305. All Elements in Two Binary Search Trees # Medium # 547 # 24 # Add to List # Share # 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] # Exam...
e456af0fd91b326017b54d082eb08cf8da3eecdb
akimi-yano/algorithm-practice
/lc/review_991.BrokenCalculator.py
1,846
4.03125
4
# 991. Broken Calculator # Medium # 1076 # 146 # Add to List # Share # There is a broken calculator that has the integer startValue on its display initially. In one operation, you can: # multiply the number on display by 2, or # subtract 1 from the number on display. # Given two integers startValue and target, ret...
a9a370564bc0a7be2ec1fad7ee2500b557db6b67
akimi-yano/algorithm-practice
/lc/review2_113.PathSumII.py
1,769
3.859375
4
# 113. Path Sum II # Medium # 5707 # 122 # Add to List # Share # Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values in the path equals targetSum. Each path should be returned as a list of the node values, not node references. # A root-to-leaf pa...
3302565fdd60616b47c498db862e15282499056b
akimi-yano/algorithm-practice
/lc/review_897.IncreasingOrderSearchTree.py
1,342
4
4
# 897. Increasing Order Search Tree # Easy # 2407 # 600 # Add to List # Share # Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child. # Example 1: # Input: root = [5,3...
cdf6172cdbd928db735048ba282a64addcf214a6
akimi-yano/algorithm-practice
/lc/1963.MinimumNumberOfSwapsToMake.py
2,188
3.796875
4
# 1963. Minimum Number of Swaps to Make the String Balanced # Medium # 53 # 6 # Add to List # Share # You are given a 0-indexed string s of even length n. The string consists of exactly n / 2 opening brackets '[' and n / 2 closing brackets ']'. # A string is called balanced if and only if: # It is the empty strin...
da74d955658e5ad6d9a9bfa7a6b3758ff82353bd
akimi-yano/algorithm-practice
/lc/1625.LexicographicallySmallestStrin.py
4,029
4.1875
4
# 1625. Lexicographically Smallest String After Applying Operations # Medium # 27 # 77 # Add to List # Share # You are given a string s of even length consisting of digits from 0 to 9, and two integers a and b. # You can apply either of the following two operations any number of times and in any order on s: # Add...
c270c633f372cd386480d2e4c491e0913ce4d45c
akimi-yano/algorithm-practice
/lc2/explore_top_interview_questions_easy/HouseRobber.py
1,565
3.578125
4
''' 198. House Robber Medium 17.8K 336 Companies You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the...
552fa157624d4971e8375a2371694bd9452900c0
akimi-yano/algorithm-practice
/lc/150.EvaluateReversePolishNotation.py
5,581
4
4
# 150. Evaluate Reverse Polish Notation # Evaluate the value of an arithmetic expression in Reverse Polish Notation. # Valid operators are +, -, *, /. Each operand may be an integer or another expression. # Note: # Division between two integers should truncate toward zero. # The given RPN expression is always valid...
c722ac6a086d1e1ff93a218f966d22037a57a542
akimi-yano/algorithm-practice
/lc/1652.DefuseTheBomb.py
2,462
3.671875
4
# 1652. Defuse the Bomb # Easy # 33 # 11 # Add to List # Share # You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array code of length of n and a key k. # To decrypt the code, you must replace every number. All the numbers are replaced simultaneously. # If k ...
1129535e51815e427b0ab469a65e30f55b32cf23
akimi-yano/algorithm-practice
/lc/1359.CountAllValidPickupAndDeliv.py
2,034
3.9375
4
# 1359. Count All Valid Pickup and Delivery Options # Hard # 564 # 81 # Add to List # Share # Given n orders, each order consist in pickup and delivery services. # Count all valid pickup/delivery possible sequences such that delivery(i) is always after of pickup(i). # Since the answer may be too large, return i...
4628c321ff67d6107213f3a63c72b26e39e425dd
akimi-yano/algorithm-practice
/lc/74.Search2DMatrix.py
2,078
3.875
4
# 74. Search a 2D Matrix class Solution: # def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: # if len(matrix)==0 or len(matrix[0])==0: # return False # # print(len(matrix[0])) # low = 0 # high = len(matrix)-1 # mid = (low+high)//2 # whi...
be72fa635d524110a80eed1d86fdd70eeb12f092
akimi-yano/algorithm-practice
/lc/1519.NumberOfNodesInTheSubTree.py
5,401
3.671875
4
# 1519. Number of Nodes in the Sub-Tree With the Same Label # User Accepted:2035 # User Tried:4104 # Total Accepted:2078 # Total Submissions:9854 # Difficulty:Medium # Given a tree (i.e. a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. The root of...
a735f6940b76d9f9fbe10f71f9c1966cbd4006e3
akimi-yano/algorithm-practice
/lc/936.StampingTheSequence.py
5,682
4.1875
4
# 936. Stamping The Sequence # Hard # 402 # 105 # Add to List # Share # You want to form a target string of lowercase letters. # At the beginning, your sequence is target.length '?' marks. You also have a stamp of lowercase letters. # On each turn, you may place the stamp over the sequence, and replace every let...
c01105459276bbdc5b5a227d00923b6b920b73a8
akimi-yano/algorithm-practice
/lc/review_127.WordLadder.py
3,145
3.78125
4
# 127. Word Ladder # Hard # 6705 # 1561 # Add to List # Share # A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that: # Every adjacent pair of words differs by a single letter. # Every si for 1 <= i <= k is in ...
783d3393b6b35728c27d0dab6be496f47d19865c
akimi-yano/algorithm-practice
/lc/review_189.RotateArray.py
2,215
4.09375
4
# 189. Rotate Array # Medium # 3555 # 870 # Add to List # Share # Given an array, rotate the array to the right by k steps, where k is non-negative. # Follow up: # Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem. # Could you do it in-place with O(1) extra spa...
3fcc986b7d07955fb9fbfba612218a169a540c3d
akimi-yano/algorithm-practice
/lc/review_1721.SwappingNodesInALinkedList.py
3,445
3.90625
4
# 1721. Swapping Nodes in a Linked List # Medium # 372 # 26 # Add to List # Share # You are given the head of a linked list, and an integer k. # Return the head of the linked list after swapping the values of the kth node from the beginning and the kth node from the end (the list is 1-indexed). # Example 1: ...
a460fe73ea7c8e85bcfe9599e9aaeefe678f4cc0
akimi-yano/algorithm-practice
/lc/1526.MinimumNumberOfIncrements.py
2,175
3.71875
4
# 1526. Minimum Number of Increments on Subarrays to Form a Target Array # Given an array of positive integers target and an array initial of same size with all zeros. # Return the minimum number of operations to form a target array from initial if you are allowed to do the following operation: # Choose any subarray...
b6160685291db549b032d07e7ef244d8e2761703
akimi-yano/algorithm-practice
/lc/47.PermutationsII.py
949
3.640625
4
# 47. Permutations II # Medium # 2471 # 69 # Add to List # Share # Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order. # Example 1: # Input: nums = [1,1,2] # Output: # [[1,1,2], # [1,2,1], # [2,1,1]] # Example 2: # Input: nums = [1,2,3] # ...
7fc8de5fe1655acbddff297469514bc966682027
akimi-yano/algorithm-practice
/lc/1046.LastStoneWeight.py
1,474
3.5
4
# 1046. Last Stone Weight # We have a collection of stones, each stone has a positive integer weight. # Each turn, we choose the two heaviest stones 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...
83fc222b0de6ccc35d9c6979bb5c2eb265779f92
akimi-yano/algorithm-practice
/lc/841.KeysAndRooms.py
1,585
3.71875
4
# 841. Keys and Rooms # Medium # 1688 # 121 # Add to List # Share # There are N rooms and you start in room 0. Each room has a distinct number in 0, 1, 2, ..., N-1, and each room may have some keys to access the next room. # Formally, each room i has a list of keys rooms[i], and each key rooms[i][j] is an intege...
ab1caa68f672a8af00b01d35c2d79a858c0de60f
akimi-yano/algorithm-practice
/lc/1755.ClosestSubsequenceSum.py
3,644
3.859375
4
# 1755. Closest Subsequence Sum # Hard # 54 # 18 # Add to List # Share # You are given an integer array nums and an integer goal. # You want to choose a subsequence of nums such that the sum of its elements is the closest possible to goal. That is, if the sum of the subsequence's elements is sum, then you want to ...
201e5eb0545be43fceece844312c43566b1e0818
akimi-yano/algorithm-practice
/oc/328_Odd_Even_Linked_List.py
2,239
4.1875
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 complexity....
cd2f7cff4ed38b6c19dff23f26e3ab7d6c6abb49
akimi-yano/algorithm-practice
/lc/review_279.PerfectSquares.py
2,034
3.859375
4
# 279. Perfect Squares # Medium # 5369 # 256 # Add to List # Share # Given an integer n, return the least number of perfect square numbers that sum to n. # A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1, 4, 9, and 16 ar...
0f7c843699464b6eca511cee918cd57657f91db3
akimi-yano/algorithm-practice
/grokkingDP/problems/pattern1.py
4,585
3.703125
4
# pattern 1 : 0/1 knapsack # A: 0/1 Knapsack # Introduction # # Given the weights and profits of ‘N’ items, we are asked to put these items in a knapsack which has a capacity ‘C’. The goal is to get the maximum profit from the items in the knapsack. Each item can only be selected once, as we don’t have multiple quanti...
241ca9304d4b204bfa717ea366abdb73046e7547
akimi-yano/algorithm-practice
/lc/1338.ReduceArraySizeToTheHalf.py
1,686
4.15625
4
# 1338. Reduce Array Size to The Half # Medium # 767 # 64 # Add to List # Share # Given an array arr. You can choose a set of integers and remove all the occurrences of these integers in the array. # Return the minimum size of the set so that at least half of the integers of the array are removed. # Example 1...