1
00:00:00,840 --> 00:00:01,600
Hi, everyone.

2
00:00:01,620 --> 00:00:07,230
So in this video, we will be writing the code for this problem, using the mathematical approach.

3
00:00:09,030 --> 00:00:13,010
So first let's rename the variable or rename the edit name.

4
00:00:13,680 --> 00:00:20,120
So let's name it array or let's name it victory, or we can also rename it Doueiri.

5
00:00:20,610 --> 00:00:21,900
Yeah, it seems fine.

6
00:00:22,860 --> 00:00:23,110
Right.

7
00:00:23,220 --> 00:00:26,030
So the two equations was this was our first one.

8
00:00:26,430 --> 00:00:36,780
That is the actual sum, that is the Edison, Brait, Edison and some from one to N is basically our

9
00:00:36,840 --> 00:00:46,860
A minus B and then we have one more question, which is some and this was the Edison that is actual

10
00:00:46,860 --> 00:00:47,160
sum.

11
00:00:48,000 --> 00:00:54,090
And we need to take square of all the elements minus some square of all the elements.

12
00:00:54,600 --> 00:01:00,830
And this was our E squared, minus B scrapyard was A minus B and A plus B, right.

13
00:01:01,020 --> 00:01:04,530
So let's try to find out this value and this value.

14
00:01:04,650 --> 00:01:05,750
Let's do that.

15
00:01:05,970 --> 00:01:09,710
So let's take the variable sum.

16
00:01:11,550 --> 00:01:15,030
So this is basically our actual sum, right?

17
00:01:15,360 --> 00:01:18,360
So let's rename two or not.

18
00:01:18,360 --> 00:01:21,150
Somebody will let this complete value.

19
00:01:23,480 --> 00:01:31,700
This complete value, I am denoting this complete value with some and this complete value, I am denoting

20
00:01:31,700 --> 00:01:33,650
this value as square some.

21
00:01:34,800 --> 00:01:37,400
Right, so let's try to find out some answers.

22
00:01:37,420 --> 00:01:45,480
And so initially it will be zero, obviously, and obviously what will be the square?

23
00:01:45,480 --> 00:01:50,300
Some square, some will also be easy to find.

24
00:01:50,460 --> 00:01:52,530
And let's take one variable.

25
00:01:53,990 --> 00:01:57,720
Them, right, so now let's it over the area.

26
00:01:57,770 --> 00:02:00,010
We need to hydrate, so I call zero.

27
00:02:00,020 --> 00:02:05,750
I less then added retard size I plus plus.

28
00:02:06,860 --> 00:02:08,840
So what is this temp variable?

29
00:02:08,840 --> 00:02:11,900
This temp variable is nothing but the eighth element of the adding.

30
00:02:12,950 --> 00:02:20,900
Fine now for finding out the value of some what you will do, so for finding out some the actual some

31
00:02:20,900 --> 00:02:26,590
will get incremented by the terrorism and will get the by this Anderson.

32
00:02:26,800 --> 00:02:27,220
Right.

33
00:02:27,590 --> 00:02:30,910
So basically what I want to say it is in this some.

34
00:02:32,890 --> 00:02:43,330
I will add the revenue which is up, and from this sum, I am going to decrease the value and the value

35
00:02:43,330 --> 00:02:47,180
which I'm going to decrease is basically a plus one, right.

36
00:02:47,890 --> 00:02:51,720
This is a what we need to do.

37
00:02:51,730 --> 00:02:58,000
We need to decrease the value once sorry, one plus two plus three plus tail end.

38
00:02:58,000 --> 00:03:03,280
And we need to take decrement rate so the sum will decrease rate negative.

39
00:03:03,400 --> 00:03:07,860
So I'm decreasing the value and the value of a zero I need to one.

40
00:03:08,020 --> 00:03:09,160
So that's a plus one.

41
00:03:09,670 --> 00:03:10,090
Right.

42
00:03:10,480 --> 00:03:12,250
And we will do exactly the same.

43
00:03:12,760 --> 00:03:13,750
Four-Square some.

44
00:03:16,010 --> 00:03:17,980
So Four-Square, somebody will do

45
00:03:20,930 --> 00:03:26,090
this is our square some and we will add the square.

46
00:03:28,910 --> 00:03:29,930
So that is.

47
00:03:32,020 --> 00:03:35,980
Temp in the temp, we need to take this square.

48
00:03:43,580 --> 00:03:56,700
Similarly, we need to decrease the values to square some minus equals to this is our I I plus one into

49
00:03:56,710 --> 00:03:57,710
two plus one.

50
00:03:58,460 --> 00:03:58,920
Right.

51
00:03:58,940 --> 00:04:02,340
And this value may overflow.

52
00:04:02,900 --> 00:04:04,040
So let's do one thing.

53
00:04:04,160 --> 00:04:07,060
Let's typecast these values into Longlong.

54
00:04:07,730 --> 00:04:08,080
Right.

55
00:04:08,180 --> 00:04:12,610
These are like vandevelde multipoint so their values might overflow.

56
00:04:13,280 --> 00:04:21,370
So to avoid overflow, to avoid integer overflow, let's typecast these integer values into long long

57
00:04:23,060 --> 00:04:23,390
fine.

58
00:04:24,320 --> 00:04:26,360
So when we will come out of this loop.

59
00:04:27,830 --> 00:04:29,390
So I have two values now.

60
00:04:29,660 --> 00:04:30,580
I have two values.

61
00:04:30,590 --> 00:04:31,880
Now I know the value of some.

62
00:04:33,190 --> 00:04:35,200
And I know the value of square some.

63
00:04:36,130 --> 00:04:42,190
So let's try to find out if we have the value of A minus B, let's try to find out A plus B, so for

64
00:04:42,190 --> 00:04:49,600
finding out plus B into Divided Square, some by E minus B and C minus be some sort of square sum divided

65
00:04:49,600 --> 00:04:52,360
by a sum will give you A plus B eight.

66
00:04:53,860 --> 00:05:01,240
So let's take another variable long, long, and this value is A plus B, so what should be the variable

67
00:05:01,240 --> 00:05:06,400
name, the variable name, let's say A plus B or what should be the variable name?

68
00:05:07,240 --> 00:05:08,080
Some maybe.

69
00:05:09,030 --> 00:05:10,030
Made the video.

70
00:05:10,470 --> 00:05:16,230
Maybe that is A plus B, so this value will be us square some.

71
00:05:19,480 --> 00:05:23,930
Some divided by your son, right?

72
00:05:24,490 --> 00:05:32,990
So now you have the value of A plus B and what is this some this sum is nothing.

73
00:05:33,010 --> 00:05:36,240
This is the value of A minus B.

74
00:05:37,480 --> 00:05:45,340
And now if we will add this, if we will add some and we will add some ebby, so you will get the value

75
00:05:45,340 --> 00:05:52,570
of a rate so integer that we need to find out this is nothing.

76
00:05:52,570 --> 00:05:58,390
But you will add some plus you will add some AB.

77
00:05:59,730 --> 00:06:04,860
And divided by two rate Ed, divided by two.

78
00:06:10,510 --> 00:06:20,500
So once you have the value of a what will be the value of B, so value of B will be so the value of

79
00:06:20,800 --> 00:06:22,080
B will be.

80
00:06:22,090 --> 00:06:24,610
So if we will see this is A plus B, right.

81
00:06:24,820 --> 00:06:25,810
You know, the value of it.

82
00:06:26,110 --> 00:06:31,660
So what put it here, that is some A, B minus E, right.

83
00:06:32,890 --> 00:06:39,830
So B is nothing but simply you are some A, B minus A.

84
00:06:40,570 --> 00:06:44,110
So you have the value of A and B and we need to return back to.

85
00:06:44,110 --> 00:06:44,530
Right.

86
00:06:44,770 --> 00:06:54,910
The return type is basically you need to return and add a vector and let's say answer and we need to

87
00:06:54,910 --> 00:06:56,290
insert A and B so on.

88
00:06:56,290 --> 00:06:58,240
Sadaat push back.

89
00:06:59,380 --> 00:07:04,630
You know, which is coming twice and the Vinoba which is missing,

90
00:07:07,540 --> 00:07:09,650
right, and we will return our answer.

91
00:07:10,660 --> 00:07:15,370
So let's try to test and if everything works, fine, then we'll submit.

92
00:07:17,360 --> 00:07:22,870
OK, so they should be spelling mistakes.

93
00:07:22,880 --> 00:07:23,980
They should be square some.

94
00:07:32,500 --> 00:07:34,330
Yep, so let's try to submit now.

95
00:07:39,920 --> 00:07:42,260
So, yeah, our solution is working fine.

96
00:07:46,700 --> 00:07:53,600
Right, and now let's discuss their time in the space complexity for this, so it's very simple and

97
00:07:53,600 --> 00:07:54,310
very obvious.

98
00:07:55,010 --> 00:07:56,740
So what is our time complexity?

99
00:07:57,200 --> 00:07:59,980
So we are trading over this area, right.

100
00:07:59,990 --> 00:08:02,360
And we are doing constant work inside.

101
00:08:02,630 --> 00:08:08,660
So a precise number of elements and certain complexities big often if we talk about the space complexity,

102
00:08:08,660 --> 00:08:10,990
we are creating fewer tables here and there.

103
00:08:11,000 --> 00:08:12,870
And this is vectoring dancer.

104
00:08:12,980 --> 00:08:18,490
So the question is asking us to return vector and this rectories of size only two, it will contain

105
00:08:18,500 --> 00:08:19,400
only two elements.

106
00:08:19,730 --> 00:08:22,190
So we can say the space complexity is constant.

107
00:08:22,590 --> 00:08:22,860
Right.

108
00:08:23,140 --> 00:08:25,190
So this is the time and the space complexity.

109
00:08:25,190 --> 00:08:27,380
And this is much better than the map approach.

110
00:08:27,560 --> 00:08:32,419
In case of map, that time was when and the space was also big off.

111
00:08:32,419 --> 00:08:35,570
And so we are able to reduce space.

112
00:08:35,600 --> 00:08:38,770
So this algorithm is better than the map when approach.

113
00:08:38,780 --> 00:08:39,140
Right.

114
00:08:39,289 --> 00:08:41,080
So this is all about this device.

115
00:08:41,390 --> 00:08:42,799
I will see you in the next one.

116
00:08:42,830 --> 00:08:43,400
Thank you.

