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?
- Understand the Problem:
- Read and comprehend the problem statement.
- Clarify Doubts:
- Ask the interviewer for clarification if needed.
- Ask Questions:
- Gather more information about the problem.
- Design a Plan:
- Devise an approach to solve the problem.
- Break Down the Problem:
- Divide the problem into smaller subproblems if necessary.
- Choose the Right Data Structures and Algorithms:
- Select appropriate tools based on problem requirements.
- Write Pseudocode:
- Outline the solution logic without worrying about syntax.
- Code Implementation:
- Write the actual code following best practices.
- Test Your Solution:
- Verify correctness and robustness with test cases.
- Optimize if Necessary:
- Improve time or space complexity if possible.
- Handle Errors and Edge Cases:
- Ensure graceful handling of errors and edge cases.
- Review and Debug:
- Check for errors and bugs, and troubleshoot as needed.
- Communicate Your Thought Process:
- Explain your approach and reasoning to the interviewer.
- Be Flexible and Adaptive:
- Adapt your approach based on feedback or new insights.
- Practice Regularly:
- Improve problem-solving skills through practice and mock interviews.
2. If you forget a builtin method, use 'print(dir())' in interactive terminal
This also works on your own methods as well
print(dir(list))
['__add__', '__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__',__DUNDER_METHODS__ 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
For more indepth information use help(list), but remember to use q to quit
| append(self, object, /)
| Append object to the end of the list.
|
| clear(self, /)
| Remove all items from list.
|
| copy(self, /)
| Return a shallow copy of the list.
|
| count(self, value, /)
| Return number of occurrences of value.
|
| extend(self, iterable, /)
| Extend list by appending elements from the iterable.
|
| index(self, value, start=0, stop=9223372036854775807, /)
| Return first index of value.
|
| Raises ValueError if the value is not present.
|
| insert(self, index, object, /)
| Insert object before index.
|
| pop(self, index=-1, /)
| Remove and return item at index (default last).
|
| Raises IndexError if list is empty or index is out of range.
|
| remove(self, value, /)
| Remove first occurrence of value.
|
| Raises ValueError if the value is not present.
|
| reverse(self, /)
| Reverse *IN PLACE*.
|
| sort(self, /, *, key=None, reverse=False)
| Sort the list in ascending order and return None.
|
| The sort is in-place (i.e. the list itself is modified) and stable (i.e. the
| order of two equal elements is maintained).
|
| If a key function is given, apply it once to each list item and sort them,
| ascending or descending, according to their function values.