What is Mountain array?? | Sololearn: Learn to code for FREE!
+ 3

What is Mountain array??

Can anybody help me to get what exactly mountain array is? I am solving leetcode questions and i see some questions on mountain array.. and i don't know what it is, so please comment what you understood with mountain array in simplest words...

15th Jan 2023, 10:03 AM
Rajeev Sharma
Rajeev Sharma - avatar
2 Antworten
+ 10
An array of numbers is considered a mountain array if numbers increase up till one point, then decreases till the end. Imagine climbing a mountain- You go uphill till the peak, then it's downhill from there. E.g. { 1, 2, 3, 4, 3, 2, 1 } { 2, 4, 5, 10, 9, 6 } are mountain arrays. { 2, 1, 3, 5, 4, 3, 2 } is not a mountain array, because 2 -> 1 is not increasing in value. { 1, 3, 5, 3, 4, 1 } is not a mountain array, because 3 -> 4 is not decreasing. Leetcode actually does a great job explaining it with the diagrams. If there are specific number arrangements that you are confused about, you can list them so that it is easier to explain what is or isn't a valid mountain array and why it is so for that case. https://leetcode.com/problems/valid-mountain-array/
15th Jan 2023, 10:44 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
Thank you Hatsy Rei ­čśŐ Your response is really informative for me ­čÖé
15th Jan 2023, 10:56 AM
Rajeev Sharma
Rajeev Sharma - avatar