# General Problem Solving

Consolidating some of the common patterns and problem solving methods you can try when working on problems

This list is not exhaustive! If you wish to contribute more techniques, please email me at woojiahao1234@gmail.com

Finding the median of data: focus on the definition of a median and model the solution after it

Sub-array problems: think about using sliding windows discussed under Arrays

Sub-sequence problems: think about sorting (if possible)

$O(n \log n)$ upper bound (found using Runtime Predictions)

Divide and conquer, similar to merge sort

Arrays manipulation + Binary Search such as prefix sums + binary search

Sorting + operations on sorted array

Segment Trees+ iterating over all ranges

Applying the sweep line algorithm if there are Intervals + events

Minimum/maximum across queries: try using Heaps or Double Ended Queues

Heaps can be used to track the minimum during any query

Double Ended Queues can be used to represent the current maximum (as the front) and potential maximums (subsequent elements) in the event where the current maximum "expires"

Last updated