Questions involving arrays and strings are the most common in coding interviews.
I give you here 16 advices that will help you to solve them: ↓
I give you here 16 advices that will help you to solve them: ↓
1. You can efficiently access both ends of an array and use the 2-pointers technique. Take advantage of that.
2. It's usually possible optimize to O(1) space a brute force solution taking O(N) space.
3. Consider the possibility of overwriting an element instead of removing it.
2. It's usually possible optimize to O(1) space a brute force solution taking O(N) space.
3. Consider the possibility of overwriting an element instead of removing it.
4. Pay attention to off-by-1 errors. They're ubiquitous.
5. When integers are encoded into arrays, consider reversing the array to have the least significant digit at the beginning
6. Learn specific utilities for subarrays available in your programming language
5. When integers are encoded into arrays, consider reversing the array to have the least significant digit at the beginning
6. Learn specific utilities for subarrays available in your programming language
7. Only preserve the integrity of an input array once explicitly required.
8. Consider using parallel logic for each dimension in multidimensional arrays.
9. Arrays can also be used to represent subsets efficiently.
8. Consider using parallel logic for each dimension in multidimensional arrays.
9. Arrays can also be used to represent subsets efficiently.
10. Instead of storing characters in a hash table, use a 256 fixed-length array. It simplifies the code and makes transparent the used amount of space
11. Languages like C# and Java provide a StringBuilder class to concatenate strings efficiently. Please make use of it.
11. Languages like C# and Java provide a StringBuilder class to concatenate strings efficiently. Please make use of it.
12. Strings are immutable in many programming languages. Consider this when concatenating strings and learn to use alternatives like arrays of chars.
13. Rolling hash is a specific technique used for string comparison. It's helpful to solve some tricky problems efficiently.
13. Rolling hash is a specific technique used for string comparison. It's helpful to solve some tricky problems efficiently.
14. Learn how to refer to characters by their ASCII values.
For example, learn how to:
- Get the ASCII value of a character
- Convert an ASCII value into a character
- Convert a digit character into its integer value
For example, learn how to:
- Get the ASCII value of a character
- Convert an ASCII value into a character
- Convert a digit character into its integer value
15. Sliding windows are a technique that comes up a lot. It usually makes it possible to improve the time complexity from quadratic to linear.
16. Learn how to implement tries for representing and storing a set of words. They help to solve advanced problems.
16. Learn how to implement tries for representing and storing a set of words. They help to solve advanced problems.
Loading suggestions...