Advertisement
samimwebdev

problem solving approach markdown

Jun 17th, 2022 (edited)
2,021
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Smarty 2.12 KB | None | 0 0
  1. # Problem Solving approach
  2.  
  3. ### 1. understanding the problem
  4.  
  5. - restate the problem in own words
  6. - what are the input and outputs
  7. - Is there enough information to solve the problem
  8. - Thinking of labelling data (don't use random label like i, j, k, a, b)
  9. - checking the example with invalid, empty input
  10.  
  11. ---
  12.  
  13. > Write the problem that takes 2 numbers and returns the sum?
  14.  
  15. ---
  16.  
  17. ```javascript
  18. //writing a function that takes /two number and returns the sum
  19. function sum(num1, num2) {
  20.   //output
  21. }
  22. sum(10, 15)
  23. ```
  24.  
  25. ### 2.Note own the details like input, output
  26.  
  27. ### 3. Start with the naive/brute force approach. First thing that comes into mind. It shows that you’re able to think well and critically (you don't need to write this code, just speak about it).
  28.  
  29. ### 4. Tell them why this approach is not the best (i.e. O(n^2) or higher, not readable, etc...)
  30.  
  31. ### 5. Walk through your approach, comment things and see where you may be able to break things.
  32.  
  33. ### 6. Before you start coding, walk through your code and write down the steps you are going to follow
  34.  
  35. ### 7. breakdown the steps and commenting is the ultimate key,Rundown of thinking process, steps. Breaking down the code will you give you the extra advantage
  36.  
  37. ```javasript
  38. function sumOfEvenSqure(inputArr){
  39.     //write code where
  40. }
  41. sumOfEvenSqure([1, 2, 4, 6, 7])
  42.  
  43. ```
  44. ### 8.start coding (simplify as necessary)
  45.  
  46. ### 9. can you write it better in terms of readability, time, space complexity?
  47.  
  48. ### 10. If your interviewer is happy with the solution, the interview usually ends here. It is also Common that the interviewer asks you extension questions
  49.  
  50. > Write a function which takes in a string and returns counts of each character in the string.
  51.  
  52. ```javascript
  53. //writing a function that takes /two number and returns the sum
  54. function countCharacter(inputStr) {
  55.   //output
  56. }
  57. countCharacter('Hello')
  58. ```
  59.  
  60. > checking the element exists between two array
  61.  
  62. function countCharacter(inputStr){
  63. //output
  64. }
  65. countCharacter("Hello")
  66.  
  67. ```javascript
  68. function isElementExists(arr1, arr2) {
  69.   //output
  70. }
  71. isElementExists(['a', 'b', 'c'], [1, 2, 3, 'z'])
  72. ```
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement