In this section, we'll:
- Learn how to apply a structured problem solving approach.
- Practice this skill by solving a couple of exercise problems.
Find the contiguous subarray within a one-dimensional array of numbers which has the largest sum
What's a contiguous subarray? https://www.quora.com/What-is-difference-between-subarray-and-contiguous-subarray
Video 1: https://www.youtube.com/watch?v=s2uRlOu4Nj8
Video 2: https://www.youtube.com/watch?v=xWOumExKGF8
Video 3: https://www.youtube.com/watch?v=wFI4xNGai6Q
Here's the final solution:
https://gitlab.com/snippets/1968149
This problem was too difficult
Don't worry. Use this problem just as an example to understand the overall problem solving process. You will soon reach a point where you'll be able to solve such problems on your own.
1. Run code on your own system:
Don't run your code directly on HackerRank or Edabit. It will be difficult for you to debug the code and you'll end up wasting a lot of time.
Instead:
- Install your programming language of choice on your system.
- Install VSCode - https://code.visualstudio.com/
- Write your own test cases
- Once the code works on your system, submit it on HackerRank / Edabit
2. Write Helper functions
- Break down your problem into small steps
- Create "helper functions" and test them individually.