1
00:00:01,060 --> 00:00:03,700
Hi everyone, let's do this question.

2
00:00:03,700 --> 00:00:12,100
You are given a string consisting of only lowercase and uppercase English alphabets and integers 0 to

3
00:00:12,100 --> 00:00:12,490
9.

4
00:00:12,700 --> 00:00:19,660
All right, write a function that will take this string as input and return the index of the first character

5
00:00:19,660 --> 00:00:21,280
that is non-repeating.

6
00:00:21,280 --> 00:00:21,790
All right.

7
00:00:21,820 --> 00:00:27,610
Now when you're doing this in an interview, feel free to ask clarifying questions so that you have

8
00:00:27,610 --> 00:00:31,270
a thorough understanding of what the question is talking about.

9
00:00:31,270 --> 00:00:37,270
Now, a possible question is you could ask, can you tell me what do you mean with first non-repeating

10
00:00:37,270 --> 00:00:37,930
character?

11
00:00:37,930 --> 00:00:41,050
Let's say this was under stress.

12
00:00:41,050 --> 00:00:46,690
And, uh, immediately you were not able to grasp the meaning of first non-repeating character.

13
00:00:46,690 --> 00:00:48,640
So there's no problem.

14
00:00:48,640 --> 00:00:50,860
You can always ask a clarifying question.

15
00:00:50,860 --> 00:00:56,590
And let's say the interviewer responds, the first character that occurs only one time.

16
00:00:56,590 --> 00:00:56,950
All right.

17
00:00:56,950 --> 00:00:58,420
So you get a good understanding.

18
00:00:58,810 --> 00:01:01,090
Now you could ask another question.

19
00:01:01,090 --> 00:01:02,440
What if it's not there?

20
00:01:02,440 --> 00:01:06,070
What if in the string there is no non-repeating character?

21
00:01:06,070 --> 00:01:10,270
Now the interviewer could say, okay, in that case just return null.

22
00:01:10,750 --> 00:01:11,230
Okay.

23
00:01:11,230 --> 00:01:16,300
And another question that you could ask is because over here you have lowercase and uppercase English

24
00:01:16,300 --> 00:01:17,200
alphabets.

25
00:01:17,200 --> 00:01:23,650
If A and a occurs small a and capital A occurs, should it be treated as repeating?

26
00:01:23,650 --> 00:01:26,290
And let's say the interviewer responds no.

27
00:01:26,290 --> 00:01:26,860
All right.

28
00:01:26,860 --> 00:01:32,560
So at this point we have developed a good understanding of what the question is asking.

29
00:01:32,560 --> 00:01:35,890
Now let's proceed and write out some test cases.

30
00:01:35,890 --> 00:01:36,160
Again.

31
00:01:36,160 --> 00:01:42,310
Remember test cases are just various inputs and what the expected output is in those scenarios.

32
00:01:42,310 --> 00:01:48,520
And you can always ask the interviewer, is it okay if we come up together with some test cases for

33
00:01:48,520 --> 00:01:49,120
the question?

34
00:01:49,120 --> 00:01:51,670
So that is always a good practice.

35
00:01:51,670 --> 00:01:54,580
Now let's go ahead and write a few test cases.

36
00:01:54,580 --> 00:02:00,010
If the string that's given to us is this 1AAB, c one AC bd.

37
00:02:00,250 --> 00:02:00,730
All right.

38
00:02:00,730 --> 00:02:03,760
Now in this case what should be the output.

39
00:02:03,760 --> 00:02:07,240
We need the index of the first non-repeating character.

40
00:02:07,240 --> 00:02:09,850
Now we can see that A is repeating over here.

41
00:02:09,850 --> 00:02:14,590
So this is not non-repeating but this small A is not repeating.

42
00:02:14,590 --> 00:02:17,470
So yes this is the first non-repeating character.

43
00:02:17,470 --> 00:02:19,540
And the index of this will be one.

44
00:02:19,540 --> 00:02:19,780
Right.

45
00:02:19,780 --> 00:02:22,240
So the output of the function has to be one.

46
00:02:22,240 --> 00:02:24,940
So this is 0123 etc..

47
00:02:24,940 --> 00:02:25,120
Right.

48
00:02:25,120 --> 00:02:27,850
So we are picking this one and that should be the output.

49
00:02:27,850 --> 00:02:31,600
What if the given string is AAAA33.

50
00:02:31,600 --> 00:02:35,110
So there is no non-repeating character in this given string.

51
00:02:35,110 --> 00:02:39,970
So in this case as per the clarification that we received the output has to be null.

52
00:02:39,970 --> 00:02:43,480
Now what if the given string is a b a?

53
00:02:43,480 --> 00:02:49,750
In this case, the first non-repeating character is this one because we treat these two differently.

54
00:02:49,750 --> 00:02:52,240
And the index over here is zero.

55
00:02:52,240 --> 00:02:54,160
So that should be the output.

56
00:02:54,160 --> 00:02:54,670
All right.

57
00:02:54,670 --> 00:02:57,460
So we have got a good understanding of the question.

58
00:02:57,460 --> 00:02:59,290
And we have written some test cases.

59
00:02:59,290 --> 00:03:02,200
And both the interviewer and you are on the same page.

60
00:03:02,200 --> 00:03:03,910
You have good clarity.

61
00:03:03,940 --> 00:03:08,560
Now let's proceed and think about ways in which we can solve this question.
