Hello, everyone, and welcome back.
So up until this point, we've worked exclusively with ARray's and we've really been working on this
two points or model in our last two questions.
So the two point technique is a great technique because it is such a good combination of understanding
how logical and abstract thinking can be applied to this technical tool as long as you understand how
to use it.
Now, this tool is actually very useful throughout not just Arae questions, but other similar data
models.
And we're going to learn them, of course, throughout this course.
This next data model that I want to focus on is actually called strings and strings are pretty much
the same thing as arrays.
But there is a couple nuances to them and how they appear in technical interviews.
But we're going to stick with arrays for a little bit longer just to make sure that we have worked and
built a solid foundation of our critical thinking model, but also that we truly, deeply understand
how these different technical techniques work with arrays because they will show up again in different
data models.
So with strings, when we learn about them in programming, we see them as a primitive type, that is
a sequence of alphanumeric characters, meaning that they can contain letters from A to Z or they can
contain numbers when it contains letters.
It doesn't necessarily have to be lowercase.
It can also be uppercase.
And strings can also contain all of these different elements combined together as long as they exist
between these two quotations.
But another way that we can see strings is we can see strings as arrays.
Just imagine that each character in the string is a element in the array.
The reason why the similarity exists is because they are linear right there.
These one dimensional left-to-right data structures and also the order of the characters in the string
appear pretty much the same way as the order of elements in an array.
And that order matters.
So when you see string questions show up in a interview, it's pretty much just some variation of an
array question.
But the main difference here is that the string questions are going to have more to do with pattern
matching, or they're going to make us use some kind of critical thinking about concepts that involve
strings in the real world.
The techniques that we apply with the raise and the critical thinking that we apply to a race is going
to be very similar with strings, but we're going to have to grow our thought process a little bit.
And this next question is actually a great example of how this abstract thinking with strings might
appear in questions.
So the question asks, given to String's S.A. return, if they equal when both are typed out, any hash
that appears in the string counts as a backspace.
So if this question is confusing, let's just quickly run through an example of what this question is
asking for.
So let's imagine we were given this string seab hash D.
Now this question talks about typing it out.
So imagine if we were to type this out from left to right, we would type C, B, and then when we hit
the hash, what we're going to do is we're going to hit backspace, so we're going to delete the B and
then we're going to type D.
So this is what that String Seab Hashd turns into, and that's that final version that actually counts
and what we're going to want it to be.
So imagine we were given two strings in this format, string, essence, string t, if we were to type
this out, we know that the hash is going to delete the B with the S leaving us with a C and with a
string T, that hash beside the Z is going to delete the Z and then we're going to end up with a C.
So when we're giving these two strings, we type them out persay into their final form as we see, and
then we see that they do match, meaning that we're going to return true in this case or false if they
don't match.
So now that we understand the question, let's verify the constraints.
So this question is a little tricky.
So there's actually quite a bit of constraints that we have to make sure we understand more so having
to do with this logic of the hash.
So the first question we might ask is, what happens when two hashas appear beside each other?
In this case, we delete the two values before the first hash, which is pretty much what you would
expect if we were to hit backspace twice on a keyboard.
So here, let's just take this string a B hash hash and the string that it finally becomes.
So here, when we type the first A, we would get A, we type the B, we get B, when we type the first
hash it would delete the B and then when we type that second hash, it would therefore delete the A,
leaving us with an empty string as the final form of this a B hash string.
Once we know that what happens to hashas when there is no character to remove.
In this case, the interviewer might respond.
It deletes nothing then just like backspace one.
So again, let's imagine we were given the string A hash hash B, if we were to type this out, we would
first type out the A, the first hash deletes that A, the second hash would delete nothing because
there's nothing in the string.
Third hash is the same as the previous one.
And then finally we would type B, B becomes the last string and this becomes the final string format
of A hash hash B.
Now, the other question we might ask is, are two empty strings equal to each other in this case?
Yes, there are two empty strings as equal.
So here we can see that if we were given an X of X, Y, Z hash and a string of a hash that with the
first S hash, the actual get deleted by the first hash, the Y would get deleted by the second hash
and the Z deleted by the third hash, leaving us with an empty string as the final format.
And with T it's the same.
The hash deletes the A and we would also be left with an empty string.
And in this case both of these characters then match and therefore we have a true to return from this
question.
Now, another important question to ask is, does case sensitivity matter because with strings, you
can't just assume that a large uppercase A. is the same as a lowercase A and here we might see.
Yes, it does.
Lowercase eight does not equal uppercase A..
Now, this is actually good for us because by default, in almost all programming languages, comparison
between characters, lowercase, an uppercase, if they're the same character, often yields false.
So when you compare a lowercase A to an uppercase and javascript, you're going to get false.
If this question asked us a different thing and let's say when we asked this case sensitivity question,
they say, no, it does not matter, assume that a lowercase A and an uppercase are equal.
What we would normally do is just take any strings and lowercase the entire thing, because sensitivity
in that case doesn't matter, whereas here it does.
So we can just rely on the default behavior of our programming language.
And with this we have enough of our constraints so that we can move on to the next step, which is where
we write out some test cases.
And that's what we're going to do in the next lesson.