1
00:00:00,890 --> 00:00:01,820
Hi everyone.

2
00:00:01,820 --> 00:00:03,410
Let's do this question.

3
00:00:03,410 --> 00:00:11,150
Let's define a peculiar type of array in which each element is either an integer or another peculiar

4
00:00:11,150 --> 00:00:11,600
array.

5
00:00:11,870 --> 00:00:12,350
All right.

6
00:00:12,350 --> 00:00:16,730
So over here this indicates that you have a peculiar type of array.

7
00:00:16,730 --> 00:00:20,570
And each element is either an integer or again another peculiar array.

8
00:00:20,570 --> 00:00:23,450
So notice that this indicates recursion right.

9
00:00:23,450 --> 00:00:27,620
So this is a hint that we are dealing with something that can be solved with recursion.

10
00:00:27,620 --> 00:00:29,030
Now let's proceed.

11
00:00:29,030 --> 00:00:32,180
Assume that a peculiar array is never empty.

12
00:00:32,180 --> 00:00:38,360
Write a function that will take a peculiar array as its input and find the sum of its elements.

13
00:00:38,360 --> 00:00:41,360
All right, so we have to just take in that array and find the sum.

14
00:00:41,360 --> 00:00:43,280
If an array is an element.

15
00:00:43,990 --> 00:00:48,370
In the peculiar array, you have to convert it to its equivalent value.

16
00:00:48,400 --> 00:00:48,940
All right.

17
00:00:48,940 --> 00:00:54,760
So if the element is an array then you have to convert it to its equivalent value so that you can sum

18
00:00:54,760 --> 00:00:56,230
it with the other elements.

19
00:00:56,230 --> 00:00:56,590
All right.

20
00:00:56,590 --> 00:00:59,800
So otherwise you won't be able to sum an integer and an array.

21
00:00:59,830 --> 00:01:06,760
Now equivalent value of an array is the sum of its elements raised to the number which represents how

22
00:01:06,760 --> 00:01:08,110
far nested it is.

23
00:01:08,110 --> 00:01:09,670
So you have to raise it right.

24
00:01:09,670 --> 00:01:10,540
Raise to a power.

25
00:01:10,540 --> 00:01:11,740
So it's an exponent.

26
00:01:11,830 --> 00:01:13,810
For example two three.

27
00:01:13,810 --> 00:01:17,620
And then you have this element over here which is an array 412.

28
00:01:17,650 --> 00:01:22,420
Now for this to find the sum you have to two plus three.

29
00:01:22,420 --> 00:01:25,150
And then you have to convert this to its equivalent value.

30
00:01:25,150 --> 00:01:29,110
And over here it said that's four plus one plus two to the power two.

31
00:01:29,110 --> 00:01:29,680
Right.

32
00:01:30,040 --> 00:01:35,290
So it is raised to the number which represents how far nested it is.

33
00:01:35,290 --> 00:01:37,870
So this is nested in to level two right.

34
00:01:37,870 --> 00:01:40,480
So that's why we have to the power two over here.

35
00:01:40,480 --> 00:01:43,120
Now in this case we have one two.

36
00:01:43,150 --> 00:01:44,440
So we are adding these two.

37
00:01:44,440 --> 00:01:46,540
And then over here we have seven.

38
00:01:46,540 --> 00:01:48,220
And then we have this element over here.

39
00:01:48,220 --> 00:01:49,120
And we have two.

40
00:01:49,150 --> 00:01:56,080
So seven plus the equivalent value of this element plus two to the power two because this is the second

41
00:01:56,080 --> 00:01:56,860
level right.

42
00:01:56,860 --> 00:02:01,870
And for the equivalent value of this one over here notice we have three plus four to the power three

43
00:02:01,870 --> 00:02:03,340
because this is the third level.

44
00:02:03,340 --> 00:02:08,890
Now you can also say that what this is doing over here is that if you have let's say an array with just

45
00:02:08,890 --> 00:02:15,220
three elements one, two, three, what we're doing is one plus two plus three to the power one because

46
00:02:15,220 --> 00:02:17,140
this is of level one right.

47
00:02:17,140 --> 00:02:18,640
So we have these elements.

48
00:02:19,150 --> 00:02:21,070
So I hope you have understood the question.

49
00:02:21,070 --> 00:02:23,620
Let's again summarize what we have understood.

50
00:02:23,620 --> 00:02:27,010
So we will be given a non-empty peculiar array.

51
00:02:27,010 --> 00:02:30,190
And then we have to find the sum of that peculiar array.

52
00:02:30,190 --> 00:02:32,680
And the sum is the sum of the elements.

53
00:02:32,680 --> 00:02:37,720
Now if the element of the array is an is an array itself, then you have to convert.

54
00:02:37,720 --> 00:02:40,810
For example, over here you have two which is an element which is a three.

55
00:02:40,810 --> 00:02:41,560
This is an integer.

56
00:02:41,560 --> 00:02:43,420
So yes two and three can be added.

57
00:02:43,420 --> 00:02:46,420
But then the next element over here is 412.

58
00:02:46,450 --> 00:02:47,860
So there should be a comma over here.

59
00:02:47,860 --> 00:02:49,270
So that's 412.

60
00:02:49,270 --> 00:02:53,530
And if that is the case then this has to be converted to its equivalent number.

61
00:02:53,530 --> 00:02:55,930
Only then it can be added to two plus three.

62
00:02:55,930 --> 00:02:56,320
Right.

63
00:02:56,320 --> 00:03:00,370
And for this we have to find its sum which is four plus one plus two.

64
00:03:00,370 --> 00:03:06,070
And it has to be raised to the power where the level is, where it's raised, to the number which represents

65
00:03:06,070 --> 00:03:07,600
how far nested it is.

66
00:03:07,600 --> 00:03:10,600
So this is the this is two levels deep right.

67
00:03:10,600 --> 00:03:12,550
This is level one and this is level two.

68
00:03:12,580 --> 00:03:14,410
So that's why we are raising to the power two.

69
00:03:14,440 --> 00:03:17,350
Now in this example this was three levels deep.

70
00:03:17,350 --> 00:03:18,310
This is level one.

71
00:03:18,310 --> 00:03:19,270
This is level two.

72
00:03:19,270 --> 00:03:20,620
And then this is level three.

73
00:03:20,620 --> 00:03:23,590
So over here we have three plus four to the power three.

74
00:03:23,590 --> 00:03:28,840
And then we add that to seven and two and raise it to the power two.

75
00:03:28,840 --> 00:03:31,780
So we get the equivalent value of this element over here.

76
00:03:31,780 --> 00:03:33,700
And that is added to one and two.

77
00:03:33,700 --> 00:03:34,150
All right.

78
00:03:34,150 --> 00:03:35,500
So this is the question over here.

79
00:03:35,500 --> 00:03:39,160
And again notice over here we saw something interesting in the question.

80
00:03:39,160 --> 00:03:42,760
When we read it we it's mentioned over here we have a particular type of array.

81
00:03:42,760 --> 00:03:46,510
And each element is either an integer or another peculiar array.

82
00:03:46,510 --> 00:03:48,280
So this indicates recursion right.

83
00:03:48,280 --> 00:03:52,810
So we have something and something inside that can also be that something.

84
00:03:52,810 --> 00:03:55,000
So over here this indicates recursion.

85
00:03:55,000 --> 00:03:58,450
So these type of problems typically can be solved with recursion.

86
00:03:58,450 --> 00:03:59,050
All right.

87
00:03:59,050 --> 00:04:00,820
So we have read the question.

88
00:04:00,820 --> 00:04:01,870
We have understood it.

89
00:04:01,870 --> 00:04:07,240
Now let's proceed and write a few test cases so that we get a good understanding of the question.

90
00:04:07,240 --> 00:04:10,300
And then we will look at how we can solve this question.

91
00:04:10,300 --> 00:04:12,790
Again we have a few test cases over here.

92
00:04:12,790 --> 00:04:16,720
Let's again write a few more so that we get familiarized with the question.

93
00:04:17,670 --> 00:04:18,060
All right.

94
00:04:18,060 --> 00:04:20,040
Now let's take a very simple case.

95
00:04:20,040 --> 00:04:22,980
Let's say the array which is given to us is one, two, three.

96
00:04:22,980 --> 00:04:25,290
So in this case we just need to add these.

97
00:04:25,290 --> 00:04:26,010
All right.

98
00:04:26,010 --> 00:04:29,190
One plus two plus three which is equal to six.

99
00:04:29,190 --> 00:04:29,610
Right.

100
00:04:29,610 --> 00:04:31,620
And again over here the level is one.

101
00:04:31,620 --> 00:04:35,130
So we can say that we are raising this to the power one which does not change.

102
00:04:35,130 --> 00:04:35,430
Six.

103
00:04:35,430 --> 00:04:35,790
Right.

104
00:04:35,790 --> 00:04:37,290
The answer is still six.

105
00:04:37,290 --> 00:04:40,980
Now let's say we have this array over here one two.

106
00:04:40,980 --> 00:04:43,620
And then this element is not an integer.

107
00:04:43,620 --> 00:04:44,940
It's an it's another array.

108
00:04:44,940 --> 00:04:45,390
Right.

109
00:04:45,390 --> 00:04:51,390
So in this case we have to convert this to its equivalent value so that we can add it to these two.

110
00:04:51,420 --> 00:04:55,710
So the answer over here will be one plus two plus three to the power two.

111
00:04:55,710 --> 00:04:57,150
Because this is level one.

112
00:04:57,150 --> 00:05:00,150
This bracket is level one and this bracket is level two.

113
00:05:00,150 --> 00:05:00,480
Right.

114
00:05:00,480 --> 00:05:02,430
So we have to do three to the power two.

115
00:05:02,430 --> 00:05:06,090
And this is nine nine plus two is 11 plus one is 12.

116
00:05:06,090 --> 00:05:08,340
So this gives us the answer is 12.

117
00:05:08,340 --> 00:05:11,940
And again in the question it's mentioned that the input will be non-empty.

118
00:05:11,940 --> 00:05:15,300
So we don't need to consider that case right now.

119
00:05:15,300 --> 00:05:19,440
Let's say the input is this one over here it's a little bit more complicated.

120
00:05:19,440 --> 00:05:21,120
So we have one we have two.

121
00:05:21,150 --> 00:05:27,210
So basically we need to convert this array into its equivalent value which is three plus four to the

122
00:05:27,210 --> 00:05:29,130
power of this level of the brackets.

123
00:05:29,130 --> 00:05:29,430
Right.

124
00:05:29,430 --> 00:05:30,840
So this is level one.

125
00:05:30,840 --> 00:05:32,310
This one over here is level one.

126
00:05:32,310 --> 00:05:33,120
Level one.

127
00:05:33,120 --> 00:05:34,830
This is level two right.

128
00:05:34,830 --> 00:05:36,810
This also is level two right.

129
00:05:36,810 --> 00:05:38,580
And this is within level two.

130
00:05:38,610 --> 00:05:40,320
So this is level three.

131
00:05:40,320 --> 00:05:45,900
So over here this can be converted to three plus four which is seven to the power two.

132
00:05:45,930 --> 00:05:47,760
So that is seven square right.

133
00:05:47,760 --> 00:05:49,470
Now what about this value over here.

134
00:05:49,470 --> 00:05:52,440
This two is in level three right.

135
00:05:52,440 --> 00:05:53,760
So we have to do two cube.

136
00:05:53,760 --> 00:05:55,110
So we get eight.

137
00:05:55,110 --> 00:05:57,660
Now we have still level two over here right.

138
00:05:57,660 --> 00:05:58,770
These brackets.

139
00:05:58,770 --> 00:06:02,640
So we have to do eight to the power two which gives us 64.

140
00:06:02,640 --> 00:06:05,550
So we have everything now in level one.

141
00:06:05,550 --> 00:06:07,110
So we just need to add these up.

142
00:06:07,110 --> 00:06:11,580
127 square is 49 and eight square is 64.

143
00:06:11,580 --> 00:06:14,970
So let's add them one plus two plus 49 plus 64.

144
00:06:14,970 --> 00:06:18,450
And again we could raise this to power one which is the same thing right.

145
00:06:18,450 --> 00:06:19,920
But it does not change the answer.

146
00:06:19,920 --> 00:06:21,870
And this is equal to 116.

147
00:06:21,870 --> 00:06:25,950
And this is what is expected from the function that we have to write.

148
00:06:25,950 --> 00:06:28,290
So we have got a good understanding of the question.

149
00:06:28,290 --> 00:06:34,710
Now let's proceed and think through the logic or the method which we can use to solve this problem.
