Description: We should go through every single matrix using Brute Force, backtracking, backtracking with recursively. Solution: We should go through the whole matrix. It is gonna be brute force search. This method makes the function dfs to make a path to search whole matrix. We have a materials length of Matrix(M, N), and the set of path to store our path in the matrix. Let's see the dfs functio..
Description: As we read the description of problem, we can't make another matrix for output. That means we can change the image without making matrix. Solution: We set left+=1 and right-=1, but it is out of for loop!, so that means we should change the left and top in person. The "i" means that how much apart from the beginning or the end of matrix. In example 1, after we change the value by the..
Decription: We are gonna make the variable name "Top, bottom, right_col, left_col to point the row and column you are currently in. Solution: We set the top and bottom to point to the first row and the last row. Next, we set left_column and right_column to point to the first column and the last column. We can see the sprial matrix gets value following this order: top row --> right most column --..
Description: In the m * n matrix, there are serveral values. If the value is 0, than we should change the entire row value and column value as "0". Before we do actual coding, let's think about the solution we can easily think. If we should check the entire matrix by brute force or whatever. It's gonna have O(mn) time solution. If we make another matrix, and revise the value, then it is gonna ha..
Description: If we are in nums[0], then output should be the product of all variables in array except nums[0]. I used the division operation, but the problem ask me to avoid using division operation. In addtion, the time complexity should be less than O(N), and space complexity is O(1). Solution1(not answer): We can use brute force here, but doesn't work for the problem. The reason is that time ..
Description: Basically, we will look into the array, and then find out if there are same numbers. If there is a duplication in array, then we return "True", or not then "False". Solution1(not Answer): Time Complexity for this algorithms O(N^2). In contrast, space complexity is O(1). When you submit this method, you can see the time complexity exceed for some case! That's definitely doesn't work...
Today, I studied the best time to buy and sell stock algorithms problem. Description: Solution: This code is not nested loop, so it is not gonna be O(N^2). Just O(N) time complexity. What is the difference from previous brute force algorithms? I would like to say we store two array while process in loop. We stored two value called profit and minimum price. ex) case 1: price: [7, 1, 5, 3, 6, 4] p..
The problem is called "Two Sum" with array, so I decided to solve with Python. Description: Solution: When I looked into the each variables, I used nested loop(two for loop) to find out the two variables in the array. And if the sum of two variables equal to the value of target, I return the i and j as a dictionary. Brute Force: Time complexity: O(N^2) Space complexity: O(1) Solution2: Using Has..