Cracking the coding interview Flashcards

1
Q

What did we learn abount ASCII and unicode encoding in isUnique (1.1) exercise?

“Implement an algorithm to determine if a string has all unique characters. What if you
cannot use additional data structures?”

A

the problem can be solved using bit wise operation as the input can either be ASCII or unicode encoded we could use bit mask for storing ‘1’ in the position relative to each string’s character represented in ASCII or unicode. This is done for each char, if a specific position already contains a 1 that can be easily detected using bitwise operations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how do you integer code for a character in JS

A

with charCodeAt, for example => ‘a’.charCodeAt(0)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

which one is better? Exponential or Factorial time complexity?

A

Exponential

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Ho would I check if an integer has exactly a single 1 in it’s binary representation?

A

You would simply subtract 1 to the value and do a Boolean AND between the number and the number minus 1, example
(4) 0100 (3) 0011
what we have with 3 is a series of zeros followed by 1s we can use this property to do a bit wise AND and check that the result is equal to zero

How well did you know this?
1
Not at all
2
3
4
5
Perfectly