`{"id":"d15b9d07-5d3a-4588-9292-5813c74cfc0a","name":"Temple Offerings","description":"1. Pepcoder is wishing to give offerings to all the temples along a mountain range. \r\n2. The temples are located in a row at different heights.\r\n3. You have to find the minimum number of offerings such that these conditions are fulfilled - \r\n -> If two adjacent temples are at different heights, then the temple which is situated at greater height should receive more offerings.\r\n -> If two adjacent temples are at the same height, then their offerings relative to each other does not matter. ","inputFormat":"A number N, which represents number of temples.\r\nAn array of positive integers, where every element of array represents height of temple from ground level. ","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= N &lt;= 10^8\r\n1 &lt;= arr[i] &lt;= 10^3","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\t\r\n\tpublic static int totaloffering(int[] height) {\r\n\t\t// write your code here\r\n\t\t\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint height[] = new int[n];\r\n\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\theight[i] = scn.nextInt();\r\n\t\t}\r\n\t\tSystem.out.println(totaloffering(height));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"6\r\n1 3 2 5 2 1","sampleOutput":"10\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"3083a439-4154-4843-aa37-6a4550f9394d","name":"Temple Offerings","slug":"temple-offerings","type":1}],"next":{"id":"4b26bb1d-60d1-4687-bf09-f25d7aeac509","name":"Alternating Subsequence With Maximum Sum","type":1,"slug":"alternating-subsequence-with-maximum-sum"},"prev":{"id":"53a70fde-1e46-42a9-96ca-676102e4cbf4","name":"ugly number MCQ","type":0,"slug":"ugly-number-mcq"}}}`

# Temple Offerings

1. Pepcoder is wishing to give offerings to all the temples along a mountain range. 2. The temples are located in a row at different heights. 3. You have to find the minimum number of offerings such that these conditions are fulfilled - -> If two adjacent temples are at different heights, then the temple which is situated at greater height should receive more offerings. -> If two adjacent temples are at the same height, then their offerings relative to each other does not matter.

`{"id":"d15b9d07-5d3a-4588-9292-5813c74cfc0a","name":"Temple Offerings","description":"1. Pepcoder is wishing to give offerings to all the temples along a mountain range. \r\n2. The temples are located in a row at different heights.\r\n3. You have to find the minimum number of offerings such that these conditions are fulfilled - \r\n -> If two adjacent temples are at different heights, then the temple which is situated at greater height should receive more offerings.\r\n -> If two adjacent temples are at the same height, then their offerings relative to each other does not matter. ","inputFormat":"A number N, which represents number of temples.\r\nAn array of positive integers, where every element of array represents height of temple from ground level. ","outputFormat":"Check the sample output and question video.","constraints":"1 &lt;= N &lt;= 10^8\r\n1 &lt;= arr[i] &lt;= 10^3","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\t\r\n\tpublic static int totaloffering(int[] height) {\r\n\t\t// write your code here\r\n\t\t\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint height[] = new int[n];\r\n\t\tfor (int i = 0; i < n; i++) {\r\n\t\t\theight[i] = scn.nextInt();\r\n\t\t}\r\n\t\tSystem.out.println(totaloffering(height));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"6\r\n1 3 2 5 2 1","sampleOutput":"10\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"3083a439-4154-4843-aa37-6a4550f9394d","name":"Temple Offerings","slug":"temple-offerings","type":1}],"next":{"id":"4b26bb1d-60d1-4687-bf09-f25d7aeac509","name":"Alternating Subsequence With Maximum Sum","type":1,"slug":"alternating-subsequence-with-maximum-sum"},"prev":{"id":"53a70fde-1e46-42a9-96ca-676102e4cbf4","name":"ugly number MCQ","type":0,"slug":"ugly-number-mcq"}}}`

Editor

# Temple Offerings

medium

1. Pepcoder is wishing to give offerings to all the temples along a mountain range. 2. The temples are located in a row at different heights. 3. You have to find the minimum number of offerings such that these conditions are fulfilled - -> If two adjacent temples are at different heights, then the temple which is situated at greater height should receive more offerings. -> If two adjacent temples are at the same height, then their offerings relative to each other does not matter.

## Constraints

1 <= N <= 10^8 1 <= arr[i] <= 10^3

## Format

### Input

A number N, which represents number of temples. An array of positive integers, where every element of array represents height of temple from ground level.

### Output

Check the sample output and question video.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}6 1 3 2 5 2 1```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}10 ```

Discussions

Show Discussion

Related Resources