Problems
December 19, 2022
Path crossing
We will start with the origin (0, 0)
and for each move we will update the current position. If the current position is already in the set of visited positions, then we have a path...
December 18, 2022
Check if there is a valid parentheses string path
We will use top-down memoization to solve the problem. For every opening parenthesis we add 1 to our current and for every closing parenthesis we subtract 1 from our current. If we ever reach a...
ReadDecember 18, 2022
Day of the year
We can use the datetime
module to convert the date to a datetime object and then use the timetuple
method to get the day of the year.
Time complexity: O(1)
...
December 18, 2022
Pancake sorting
We will iterate through the array, and for each element, we will find the index of the element in the array. Then we will reverse the array from the index of the element to the end of the array. Then...
ReadDecember 18, 2022
Powerful integers
We can use brute force to calculate all the possible values of x^i + y^j
until the value is less than the bound and store them in a set. Then we can return the set as a list.
Time...
December 17, 2022
Add two integers
This is a stupid problem. We can just add to numbers and return the result.
Time complexity: O(1)
Space complexity: O(1)
December 17, 2022
Apply discount to prices
We will split the sentence into words. Then we will iterate through the words, and for each word, if we found a word with the $
prefix, we will replace the amount with the discounted...
December 17, 2022
Maximum sum score of array
We will calculate the prefix sum of the array. Then we will iterate through the array, and for each element, we will find the maximum sum of the subarray that ends at the current element. Then we...
ReadDecember 17, 2022
Minimum rounds to complete all tasks
We will count the different tasks and calculate the number of rounds for each task. Then we will return the maximum number of rounds.
Time complexity: O(n)
Space complexity:...
December 17, 2022
Number of boomerangs
We will use a hashmap to store the distance between each point and the current point. Then we will iterate through the hashmap to calculate the number of boomerangs. Time complexity:...
Read