Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Sahil Kumar
A different and easier approach in O(N) Time complexity

Sahil Kumar

Jul 10, 2025

class Solution {   compare(str1, str2) {     const s1 = this.removeHash(str1.split(''))     const s2 = this.removeHash(str2.split(''))     return s1 === s2   }   removeHash(strAr) {     let j = -1     for(let i=0;i<strAr.length;i+=1){       if(strAr[i] !== "#"){         strAr[++j] = strAr[i]       }else{         j-=1         if(j < -1) j=-1       }     }     return strAr.slice(0,j+1).join('')   } }

0

0

Comments
Comments
Sahil Kumar
Sahil Kumar3 months ago

Note : O(n+m) Time Complexity

On this page