1
00:00:00,080 --> 00:00:03,590
Let's now get into the code for solving the power sum function.

2
00:00:03,590 --> 00:00:04,040
Okay.

3
00:00:04,040 --> 00:00:08,450
So over here we are given an array and we have to find the power sum.

4
00:00:08,450 --> 00:00:12,170
So let's say let sum is equal to zero.

5
00:00:12,170 --> 00:00:18,380
And finally we will be just returning math dot pow sum to the power.

6
00:00:18,380 --> 00:00:19,220
Power okay.

7
00:00:19,220 --> 00:00:22,250
Where power is what we have over here okay.

8
00:00:22,250 --> 00:00:24,470
And initially it's equal to one.

9
00:00:24,620 --> 00:00:29,870
Now what we're going to do is we are going to go through each element in the input array.

10
00:00:29,870 --> 00:00:36,080
And we know that each element in the input array is either an array itself or an integer.

11
00:00:36,080 --> 00:00:36,440
Okay.

12
00:00:36,440 --> 00:00:39,800
So we can say array dot for each.

13
00:00:39,800 --> 00:00:42,890
So we're going to go through each item of the input array.

14
00:00:43,820 --> 00:00:48,140
And for each item we are going to check whether it's an array.

15
00:00:48,140 --> 00:00:54,380
So if array dot is array item okay.

16
00:00:54,380 --> 00:00:58,040
So if it is an array then we'll be doing something.

17
00:00:58,040 --> 00:01:01,670
And if it's not an array then we will be doing something else.

18
00:01:01,670 --> 00:01:07,400
So that's the structure right now if the element at hand or the item at hand is not an array, then

19
00:01:07,400 --> 00:01:08,660
it's pretty straightforward.

20
00:01:08,660 --> 00:01:12,020
We will just have to add that value to the sum okay.

21
00:01:12,020 --> 00:01:18,530
But if it is an array, then we would have to recursively call the same power sum function.

22
00:01:18,530 --> 00:01:24,710
And at this point the array which we pass to this function would be the item that we are considering,

23
00:01:24,710 --> 00:01:26,540
because again we know that this is an array.

24
00:01:26,540 --> 00:01:28,160
So that's why we have reached over here.

25
00:01:28,160 --> 00:01:35,060
And the power which we pass to this function would be one more than what the value of power at this

26
00:01:35,060 --> 00:01:35,990
point is.

27
00:01:35,990 --> 00:01:36,320
Okay.

28
00:01:36,320 --> 00:01:37,040
And that's it.

29
00:01:37,040 --> 00:01:38,720
So this should solve the question.

30
00:01:38,720 --> 00:01:42,950
Now let's go ahead and run this code and see if it's passing all the test cases.

31
00:01:44,700 --> 00:01:47,430
And you can see that it's passing all the test cases.

32
00:01:47,430 --> 00:01:50,580
Now, in case you want some help to debug your code.

33
00:01:50,610 --> 00:01:56,520
Do make use of the user logs you are provided over here, which is available for each test case.
