This is where I leave my problem solving process and the c++ solution code.
Problem #1: kick start
Problem #2: maximum coins
Problem #3: combination lock
Problem #4: allocation
Problem #5: plates
Problem #6: workout
Problem #7: two sum
Problem #8: palindrome number
Problem #9: reverse integer
Problem #10: city finding
Problem #11: eureka
Problem #12: decomposition sum
Problem #13: maze escape
Problem #14: laboratory
Problem #15: contagion
Problem #16: merge sort
Problem #17: moving blocks
Problem #18:
Problem Link
Solution process
- Count number of a word "kick" from the begining of the sentence.
- When a word "start" shows up, add number of a word "kick" to the answer.
Note
- Make sure the substr input is covered in the string size.
- Don't make extra unneccessary addition in scanning characters.
Solution Code
Problem Link
Solution process
- Calculate every possible candidates.
- Update the maximum result to the answer.
Note
Make sure the possible maximum is covered in the type of int.
Solution Code
Problem Link
Solution process
- Calculate the number of moves wheels have to make for every numbers(1-N).
- Update the minimum value.
Note
- Be careful of data type choices.
Unsolved
- I get a TLE for the second testcase.
- I asked about it on Stack Overflow.(deleted)
Solution Code
Problem Link
Solution process
- Sort house prices in ascending order.
- Get the maximum number of houses under buget.
Solution Code
Problem Link
Solution process
- Try every combination of number of plates to take from each stack.
- Update the maximum value.
Note
- Combination with repitition : Implementable with DFS algorithm(back tracking)
Unsolved
- I get a TLE for the second testcase.
- I wonder what could be a faster algorithm than DFS that I used.
Solution Code
Problem Link
Solution process
Note
Solution Code
Problem Link
Solution process
- Sort input numbers in an ascending order.
- Check if two sum equals to target number until two sum is smaller than the target number.
Solution Code
Problem Link
Solution Process
- Cast int to string.
- Check if front characters are the same as back characters.
Solution Code
Problem Link
Solution Process
- Check the integer sign.
- Find the lowest digit of input.
- Update reverse number.
- Divide input by 10.(Delete the used digit of input.)
- Check overflow before multiplying reverse number by 10.
- Repeate.
Solution Code
Problem Link
Solution Process
DFS
- Put first node(city) to visit and check as visited.
- Find the adjacent nodes and visit if those exists. If not, pop the first node.
- Repeate until stack is empty.
Solution Code
Problem Link
Solution Process
DFS
- Put first node(city) to visit and check as visited.
- Find the adjacent nodes and visit if those exists. If not, pop the first node.
- Repeate until stack is empty.
Solution Code
Problem Link
Solution Process
DFS
- Put first node(city) to visit and check as visited.
- Find the adjacent nodes and visit if those exists. If not, pop the first node.
- Repeate until stack is empty.
Solution Code
Problem
Maze Escape
Dongbin is trapped in a NxM size rectangular maze. There lives several monsters that he needs to avoid to escape. In the beginning, Dongbin is located in cell (1,1) and the exit is located in cell (N,M). 0s are put in the cells with monsters and, 1s are put in cells without monsters. How many moves in minimum should he make to escape from the maze? You should count the starting and the finishing cells in the final answers.
Solution Process
BFS
- Put first node to visit and check as visited.
- Put every adjacent nodes that is not visited yet and pop the current node.
- Repeate until queue is empty.
Solution Code
Problem Link
Solution Process
DFS and BFS
- get the input map (0:blank 1:wall 2:virus)
- Choose 3 blank spaces to place the wall.(DFS)
- Save the temporary map with the 3 additional walls
- Spread virus all over to the temporary map.(BFS)
- Compare the number of safe places with the answer candidate.
- Update the answer if the number is bigger than the answer candidate.
Solution Code
Problem Link
Solution Process
Search
- Get the input map and push points with virus presents.
- Spread virus for S seconds in ascending order. (BFS)
- Print the value of map[Y-1][X-1];
Solution Code
Problem
Solve the sorting problem with merge sort algorithm.
Solution Process
Merge
- Set input parameters as an unsorted array, the initial, middle, and end points.
- Set indices for the former array (i) and the latter array (j).
- Set a new index k as the initial point.
- While i <= middle point and j <= end point, compare each array's element in the index and put smaller element in the sorted array's kth index.
- If while statement breaks, push the residual array's leftovers in the sorted array.
Recursive function
- Set input parameters as an unsorted array, the initial point and the end point.
- Check if the size of the array is greater than 1.
- If the size of the array is greater than 1, calculate the middle point.
- Call each recursive function giving the array ahead of the middle point and behind.
- After the dividing and conquering, merge those divided and sorted arrays.
Solution Code
Problem
Solution Process
BFS
- The solution must give the minimum value that needs BFS algorithm to solve.
- Queue is used to implement BFS Algorithm
- Unsolved yet.
Solution Code