You are on page 1of 2

MISCELLANEOUS TECHNIQUES

1. When looking for any balance, or having open or close braces, try using Stack, or else have a counter going up and down in pairs.
2. To find the commonality among different arrays or strings, we can use hash and store the frequency. If there are n array and we
have one integer common to all then frequency of the integer must be equal to n
3. To iterate over all the printable characters and save the frequency of each in the hash map, then I should use the below method
hashMap[(int)s[index]]. I am typecasting so as to get the index in the array where value needs to be stored.
4. We can do Binary search also if the matrix is sorted.
5. Bit operations to check the even odd increases the time efficiency.
6. For array questions see if it can be solved by starting from the end all the way to front
7. Use the two pointers for array sometimes, it helps.
8. Have pound defines for swapping two numbers, finding greatest among two or three number or finding vowel
#define IS_VOWEL(ch) ((ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch
== 'U') ? true:false)

#define SWAP(a, b) \
{\
(*a) ^= (*b); \
(*b) ^= (*a); \
(*a) ^= (*b); \
}

STRING RELATED QUESTIONS:


1) What is the max String length?
2) If different words in a string, then max length of each word.
3) Any special characters?
4) Any numbers?
5) Any non-printable characters?
6) Are all character’s lowercase or uppercase?
7) What is the signature of the return function?
8) What is the time complexity expected?

MISTAKES I DO FOR STRING RELATED QUESTIONS:


1) Make sure the hash map is initialized to zeros.
2) Make sure the indexes are used correctly.
3) Make sure the counter is initialized correctly (if used).
4) If creating a new character array, then make sure the last array length is one greater than what is required to have a space for
storing NULL.
5) Use pounds as much as possible, don’t hardcode the values.
6) How to move in strings containing different words. See problem 1662.
7) When returning Str, use the code return ((*(Str + index) == ‘\0’), Str)
8) When comparing two strings, makes sure the length of each is considered correctly for all corner cases

STRING and ARRAY RELATED IMPORTANT TECHNIQUES:


1) Kadane Algorithm to get the maximum sum of a sub-array.

BIT MANIPULATIONS RELATED QUESTIONS:


What questions need to be asked.
1. What is the max String length?
2. If different words in a string, then max length of each word.
3. Any special characters?
4. Any numbers?
5. Any non-printable characters?
6. Are all character’s lowercase or uppercase?
7. What is the signature of the return function?
8. What is the time complexity expected?

MISTAKES I DO FOR BIT MANIPULATIONS RELATED QUESTIONS:


1. Make sure the hash map is initialized to zeros.
2. Make sure the indexes are used correctly.
3. Make sure the counter is initialized correctly (if used).
4. If creating a new character array, then make sure the last array length is one greater than what is required to have a space for
storing NULL.
5. Use pounds as much as possible, don’t hardcode the values.
6. How to move in strings containing different words. See problem 1662.
7. When returning Str, use the code return.
BIT MANIPULATIONS RELATED IMPORTANT TECHNIQUES:

MISTAKES I DO FOR NUMBER RELATED QUESTIONS:


1. Make sure the extreme values are used as test cases to make sure no overflow is happening.

NUMBER QUESTIONS RELATED IMPORTANT TECHNIQUES:


1 If possible run through half of the number only and see if the solution can be obtained. This will help in buffer overflow.
2 Make sure the corner case of MAX negative, MAX positive, 0 , 10 and multiple of 10 are tested in the corner cases
TREES

You might also like