Title: #941 - Valid Mountain Array - LeetCode JavaScript Solutions
Open Graph Title: #941 - Valid Mountain Array - LeetCode JavaScript Solutions
X Title: #941 - Valid Mountain Array - LeetCode JavaScript Solutions
Description: Given an array of integers arr, return true if and only if it is a valid mountain array. Recall that arr is a mountain array if and only if:...
Open Graph Description: Given an array of integers arr, return true if and only if it is a valid mountain array. Recall that arr is a mountain array if and only if:...
X Description: Given an array of integers arr, return true if and only if it is a valid mountain array. Recall that arr is a mountain array if and only if:...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/valid-mountain-array
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/valid-mountain-array","name":"#941 - Valid Mountain Array - LeetCode JavaScript Solutions","description":"Given an array of integers arr, return true if and only if it is a valid mountain array. Recall that arr is a mountain array if and only if:...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number[]} arr\n * @return {boolean}\n */\nvar validMountainArray = function(arr) {\n if (arr.length < 3) return false;\n\n const peakIndex = arr.indexOf(Math.max(...arr));\n if (peakIndex === 0 || peakIndex === arr.length - 1) return false;\n\n for (let i = 1; i < peakIndex; i++) {\n if (arr[i] <= arr[i - 1]) return false;\n }\n\n for (let i = peakIndex + 1; i < arr.length; i++) {\n if (arr[i] >= arr[i - 1]) return false;\n }\n\n return true;\n};","keywords":"LeetCode 941, #941 - Valid Mountain Array, Easy, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/valid-mountain-array |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/valid-mountain-array/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0941-valid-mountain-array.js |
| Array | https://leetcodejavascript.com/tags/array |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow