Login

All Problems

Problem title

Difficulty

Avg time to solve

Frog Jump

Easy

30 mins

Longest Common Prefix After Rotation

Moderate

30 mins

Minimize Cash Flow

Easy

15 mins

Occurrence of X in a Sorted Array

Easy

26 mins

Level Order Traversal

Easy

15 mins

Top View Of The Tree

Moderate

25 mins

Rotting Oranges

Moderate

20 mins

BST queries

Easy

10 mins

Inplace rotate matrix 90 degree

Easy

12 mins

Missing number in Arithmetic progression

Easy

15 mins

Problem

Submissions

14

Avg. time to solve

30 min

Success Rate

60%

Problem Statement

```
If the given ‘HEIGHT’ array is [10,20,30,10], the answer 20 as the frog can jump from 1st stair to 2nd stair (|20-10| = 10 energy lost) and then a jump from 2nd stair to last stair (|10-20| = 10 energy lost). So, the total energy lost is 20.
```

```
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains a single integer,' N’, denoting the number of stairs in the staircase,
The next line contains ‘HEIGHT’ array.
```

```
For each test case, return an integer corresponding to the minimum energy lost to reach the last stair.
```

```
You do not need to print anything. It has already been taken care of. Just implement the given function.
```

```
1 <= T <= 10
1 <= N <= 100000.
1 <= HEIGHTS[i] <= 1000 .
Time limit: 1 sec
```

```
2
4
10 20 30 10
3
10 50 10
```

```
20
0
```

```
For the first test case,
The frog can jump from 1st stair to 2nd stair (|20-10| = 10 energy lost).
Then a jump from the 2nd stair to the last stair (|10-20| = 10 energy lost).
So, the total energy lost is 20 which is the minimum.
Hence, the answer is 20.
For the second test case:
The frog can jump from 1st stair to 3rd stair (|10-10| = 0 energy lost).
So, the total energy lost is 0 which is the minimum.
Hence, the answer is 0.
```

```
2
8
7 4 4 2 6 6 3 4
6
4 8 3 10 4 4
```

```
7
2
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code