Techniques for Solving Data Structures Problems
Techniques for Solving Data Structures Problems with Examples
General
Arrays
/* Explaining two pointers technique - 1 pointer starts from the begging and the second pointer starts from the end , they move toward each */ func reverseString(s []byte) { for i, j:= 0, len(s)-1 ; i < j && i < len(s) ; i,j= i+1, j-1 { s[i], s[j] = s[j], s[i] } }
Linked lists
1. Keep a dummy pointer
2. Slow runner runner and fast runner
3. Sentinel node doesn’t contain any value
4. Looping with linked list
5. Try to keep state outside the loop if needed , for example in reversing list
Last updated