Getting Started
1] Define the Problem and validate the inputs
Input:
- Is it a single array? Or multiple arrays?
- Are there any constraints on the size of the array?
- Can the array contain negative numbers, floating-point numbers, or other data types?
Output:
- Is it a single value, an array, or something else?
- Are there any specific requirements or constraints on the output format?
Problem Constraints:
- Are there any time complexity requirements for the solution?
- Are there any space considerations for the solution?
Edge Cases:
- Should the algorithm handle edge cases such as
- empty array?
- arrays with only one element?
- arrays with all identical elements?
2] Recognize Pattern:
Recognize the Brute Force Solution
- typically a nested loop which runs at n2
Recognize the Using Space (Hash) to Solve the Solution
HashSet's maximum size is constant (at most 26
characters), the space complexity is , meaning it is constant.
Recognize Language specific solves
Time/Space considerations:
In-place solutions (big-o):
Time Complexity:
Space Complexity:
Design Pseudocode
3]Create a function, and return the answer immediately if false, otherwise when loop is completed, it is likely true.
4] when in doubt, use Sort which is nlogn where n is the number of elements in array to go through.