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

0% completed

Vote For New Content
How about bit masking?function isPermuationInString(str, pattern) { const bit...

Zack Avino

Mar 30, 2022

How about bit masking?

function isPermuationInString(str, pattern) { const bitMaskMap = generateBitMaskMap();

let patternSum = 0; for(const char of pattern) { //generate sum for pattern patternSum += bitMaskMap.get(char); }

let windowStart = 0; let windowEnd = pattern.length - 1; let currentWindowSum = 0;

for(let i = windowStart; i

0

0

Comments
Comments
D
dan 3 years ago

Wouldn't the space complexity be O(1) since there is limit to the amount of distinct characters the pattern can have? Example, lowercase alphabet letters.

On this page