Java: Two Pointer Approach with Comments
This solution uses the two pointers approach.\nTime Complexity: O(m + n) where m and n are the lengths of strings s and t respectively;\nSpace Complexity: O(1) 
This solution uses the two pointers approach.\nTime Complexity: O(m + n) where m and n are the lengths of strings s and t respectively;\nSpace Complexity: O(1) - we do not allocate any memory (just a few variables)\n```\n    public boolean backspaceCompare(String s, String t) {\n        // Initialize pointers to the last element of both strings\n        int i = s.length() - 1; // pointer to the last element of s\n        int j = t.length() - 1; // pointer to the last element of t\n        \n        while (i >= 0 || j >= 0) {\n            int i1 = getNextValidIndex(s, i);\n            int j1 = getNextValidIndex(t, j);\n            \n            if (i1 < 0 && j1 < 0) {\n                // reached the end of both strings\n                // so both strings are equal\n                return true;\n            }\n            \n            if (i1 < 0 || j1 < 0) {\n                // reached the end of one of the strings\n                // hence s and t cannot be equal\n                return false;\n            }\n            \n            if (s.charAt(i1) != t.charAt(j1)) {\n                // current characters pointed to by the two pointers\n                // from both strings do not match\n                // hence s and t cannot be equal\n                return false;\n            }\n            \n            // Decrement pointers for next iteration\n            i = i1 - 1;\n            j = j1 - 1;\n        }\n        \n        return true;\n    }\n    \n    private static int getNextValidIndex(String str, int index) {\n        int backSpaceCount = 0;\n        \n        while (index >= 0) {\n            if (str.charAt(index) == \'#\') {\n                // found a backspace character\n                backSpaceCount++;\n            } else if (backSpaceCount > 0) {\n                // found a non-backspace character\n                backSpaceCount--;\n            } else break; // a valid character\n            \n            index--; // skip a backspace or valid character next to a backspace\n        }\n        \n        return index;\n    }\n\t```
['Two Pointers', 'Java']