1
00:00:00,300 --> 00:00:01,800
Hello, everyone, and welcome back.

2
00:00:02,700 --> 00:00:07,800
So up until this point, we've worked exclusively with ARray's and we've really been working on this

3
00:00:07,800 --> 00:00:10,950
two points or model in our last two questions.

4
00:00:11,610 --> 00:00:17,250
So the two point technique is a great technique because it is such a good combination of understanding

5
00:00:17,250 --> 00:00:24,060
how logical and abstract thinking can be applied to this technical tool as long as you understand how

6
00:00:24,060 --> 00:00:24,840
to use it.

7
00:00:25,500 --> 00:00:30,990
Now, this tool is actually very useful throughout not just Arae questions, but other similar data

8
00:00:30,990 --> 00:00:31,440
models.

9
00:00:31,590 --> 00:00:34,160
And we're going to learn them, of course, throughout this course.

10
00:00:34,680 --> 00:00:40,290
This next data model that I want to focus on is actually called strings and strings are pretty much

11
00:00:40,290 --> 00:00:41,730
the same thing as arrays.

12
00:00:42,030 --> 00:00:45,780
But there is a couple nuances to them and how they appear in technical interviews.

13
00:00:45,960 --> 00:00:51,540
But we're going to stick with arrays for a little bit longer just to make sure that we have worked and

14
00:00:51,540 --> 00:00:57,720
built a solid foundation of our critical thinking model, but also that we truly, deeply understand

15
00:00:57,720 --> 00:01:02,550
how these different technical techniques work with arrays because they will show up again in different

16
00:01:02,550 --> 00:01:03,180
data models.

17
00:01:04,270 --> 00:01:09,970
So with strings, when we learn about them in programming, we see them as a primitive type, that is

18
00:01:09,970 --> 00:01:15,550
a sequence of alphanumeric characters, meaning that they can contain letters from A to Z or they can

19
00:01:15,550 --> 00:01:18,750
contain numbers when it contains letters.

20
00:01:18,760 --> 00:01:20,590
It doesn't necessarily have to be lowercase.

21
00:01:20,590 --> 00:01:21,880
It can also be uppercase.

22
00:01:22,270 --> 00:01:27,790
And strings can also contain all of these different elements combined together as long as they exist

23
00:01:27,790 --> 00:01:29,170
between these two quotations.

24
00:01:29,770 --> 00:01:33,810
But another way that we can see strings is we can see strings as arrays.

25
00:01:34,210 --> 00:01:37,630
Just imagine that each character in the string is a element in the array.

26
00:01:38,170 --> 00:01:42,550
The reason why the similarity exists is because they are linear right there.

27
00:01:42,610 --> 00:01:48,940
These one dimensional left-to-right data structures and also the order of the characters in the string

28
00:01:48,940 --> 00:01:52,590
appear pretty much the same way as the order of elements in an array.

29
00:01:52,600 --> 00:01:54,230
And that order matters.

30
00:01:55,030 --> 00:02:00,430
So when you see string questions show up in a interview, it's pretty much just some variation of an

31
00:02:00,430 --> 00:02:01,210
array question.

32
00:02:01,300 --> 00:02:06,880
But the main difference here is that the string questions are going to have more to do with pattern

33
00:02:06,880 --> 00:02:11,860
matching, or they're going to make us use some kind of critical thinking about concepts that involve

34
00:02:11,870 --> 00:02:13,090
strings in the real world.

35
00:02:14,070 --> 00:02:18,270
The techniques that we apply with the raise and the critical thinking that we apply to a race is going

36
00:02:18,270 --> 00:02:23,690
to be very similar with strings, but we're going to have to grow our thought process a little bit.

37
00:02:23,820 --> 00:02:29,520
And this next question is actually a great example of how this abstract thinking with strings might

38
00:02:29,520 --> 00:02:30,690
appear in questions.

39
00:02:32,230 --> 00:02:41,440
So the question asks, given to String's S.A. return, if they equal when both are typed out, any hash

40
00:02:41,440 --> 00:02:44,570
that appears in the string counts as a backspace.

41
00:02:45,130 --> 00:02:49,210
So if this question is confusing, let's just quickly run through an example of what this question is

42
00:02:49,210 --> 00:02:49,920
asking for.

43
00:02:50,680 --> 00:02:54,770
So let's imagine we were given this string seab hash D.

44
00:02:55,570 --> 00:02:57,820
Now this question talks about typing it out.

45
00:02:57,820 --> 00:03:03,820
So imagine if we were to type this out from left to right, we would type C, B, and then when we hit

46
00:03:03,820 --> 00:03:07,960
the hash, what we're going to do is we're going to hit backspace, so we're going to delete the B and

47
00:03:07,960 --> 00:03:09,010
then we're going to type D.

48
00:03:09,930 --> 00:03:17,060
So this is what that String Seab Hashd turns into, and that's that final version that actually counts

49
00:03:17,250 --> 00:03:19,380
and what we're going to want it to be.

50
00:03:20,540 --> 00:03:26,360
So imagine we were given two strings in this format, string, essence, string t, if we were to type

51
00:03:26,360 --> 00:03:32,390
this out, we know that the hash is going to delete the B with the S leaving us with a C and with a

52
00:03:32,390 --> 00:03:37,930
string T, that hash beside the Z is going to delete the Z and then we're going to end up with a C.

53
00:03:38,450 --> 00:03:44,300
So when we're giving these two strings, we type them out persay into their final form as we see, and

54
00:03:44,300 --> 00:03:49,850
then we see that they do match, meaning that we're going to return true in this case or false if they

55
00:03:49,850 --> 00:03:50,490
don't match.

56
00:03:51,110 --> 00:03:55,090
So now that we understand the question, let's verify the constraints.

57
00:03:56,000 --> 00:03:57,590
So this question is a little tricky.

58
00:03:57,590 --> 00:04:02,660
So there's actually quite a bit of constraints that we have to make sure we understand more so having

59
00:04:02,660 --> 00:04:04,490
to do with this logic of the hash.

60
00:04:05,540 --> 00:04:09,800
So the first question we might ask is, what happens when two hashas appear beside each other?

61
00:04:10,750 --> 00:04:15,040
In this case, we delete the two values before the first hash, which is pretty much what you would

62
00:04:15,040 --> 00:04:17,780
expect if we were to hit backspace twice on a keyboard.

63
00:04:18,670 --> 00:04:23,290
So here, let's just take this string a B hash hash and the string that it finally becomes.

64
00:04:24,240 --> 00:04:30,210
So here, when we type the first A, we would get A, we type the B, we get B, when we type the first

65
00:04:30,210 --> 00:04:35,460
hash it would delete the B and then when we type that second hash, it would therefore delete the A,

66
00:04:35,910 --> 00:04:40,140
leaving us with an empty string as the final form of this a B hash string.

67
00:04:41,390 --> 00:04:46,220
Once we know that what happens to hashas when there is no character to remove.

68
00:04:47,400 --> 00:04:49,630
In this case, the interviewer might respond.

69
00:04:49,650 --> 00:04:52,620
It deletes nothing then just like backspace one.

70
00:04:53,370 --> 00:04:59,250
So again, let's imagine we were given the string A hash hash B, if we were to type this out, we would

71
00:04:59,250 --> 00:05:05,010
first type out the A, the first hash deletes that A, the second hash would delete nothing because

72
00:05:05,010 --> 00:05:05,940
there's nothing in the string.

73
00:05:06,300 --> 00:05:08,540
Third hash is the same as the previous one.

74
00:05:08,550 --> 00:05:14,910
And then finally we would type B, B becomes the last string and this becomes the final string format

75
00:05:14,910 --> 00:05:16,440
of A hash hash B.

76
00:05:18,150 --> 00:05:23,400
Now, the other question we might ask is, are two empty strings equal to each other in this case?

77
00:05:23,400 --> 00:05:25,800
Yes, there are two empty strings as equal.

78
00:05:26,840 --> 00:05:34,220
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

79
00:05:34,220 --> 00:05:39,710
first S hash, the actual get deleted by the first hash, the Y would get deleted by the second hash

80
00:05:39,710 --> 00:05:44,150
and the Z deleted by the third hash, leaving us with an empty string as the final format.

81
00:05:44,570 --> 00:05:45,800
And with T it's the same.

82
00:05:45,950 --> 00:05:49,360
The hash deletes the A and we would also be left with an empty string.

83
00:05:49,370 --> 00:05:55,970
And in this case both of these characters then match and therefore we have a true to return from this

84
00:05:55,970 --> 00:05:56,450
question.

85
00:05:57,620 --> 00:06:02,930
Now, another important question to ask is, does case sensitivity matter because with strings, you

86
00:06:02,930 --> 00:06:08,590
can't just assume that a large uppercase A. is the same as a lowercase A and here we might see.

87
00:06:08,600 --> 00:06:09,740
Yes, it does.

88
00:06:10,220 --> 00:06:13,100
Lowercase eight does not equal uppercase A..

89
00:06:13,820 --> 00:06:19,970
Now, this is actually good for us because by default, in almost all programming languages, comparison

90
00:06:19,970 --> 00:06:25,460
between characters, lowercase, an uppercase, if they're the same character, often yields false.

91
00:06:25,490 --> 00:06:30,500
So when you compare a lowercase A to an uppercase and javascript, you're going to get false.

92
00:06:31,560 --> 00:06:37,500
If this question asked us a different thing and let's say when we asked this case sensitivity question,

93
00:06:37,500 --> 00:06:43,720
they say, no, it does not matter, assume that a lowercase A and an uppercase are equal.

94
00:06:44,040 --> 00:06:49,890
What we would normally do is just take any strings and lowercase the entire thing, because sensitivity

95
00:06:49,890 --> 00:06:52,580
in that case doesn't matter, whereas here it does.

96
00:06:52,590 --> 00:06:56,240
So we can just rely on the default behavior of our programming language.

97
00:06:56,940 --> 00:07:03,510
And with this we have enough of our constraints so that we can move on to the next step, which is where

98
00:07:03,510 --> 00:07:05,160
we write out some test cases.

99
00:07:05,370 --> 00:07:07,620
And that's what we're going to do in the next lesson.
