Title: #565 - Array Nesting - LeetCode JavaScript Solutions
Open Graph Title: #565 - Array Nesting - LeetCode JavaScript Solutions
X Title: #565 - Array Nesting - LeetCode JavaScript Solutions
Description: A zero-indexed array A of length N contains all integers from 0 to N-1. Find and return the longest length of set S, where S[i] = {A[i], A[A...
Open Graph Description: A zero-indexed array A of length N contains all integers from 0 to N-1. Find and return the longest length of set S, where S[i] = {A[i], A[A...
X Description: A zero-indexed array A of length N contains all integers from 0 to N-1. Find and return the longest length of set S, where S[i] = {A[i], A[A...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/array-nesting
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/array-nesting","name":"#565 - Array Nesting - LeetCode JavaScript Solutions","description":"A zero-indexed array A of length N contains all integers from 0 to N-1. Find and return the longest length of set S, where S[i] = {A[i], A[A...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number[]} nums\n * @return {number}\n */\nvar arrayNesting = function(nums) {\n const history = new Set();\n let max = 0;\n for (let i = 0; i < nums.length; i++) {\n let count = 0;\n let j = i;\n while (!history.has(nums[j])) {\n j = nums[j];\n history.add(j);\n count++;\n }\n max = Math.max(max, count);\n }\n return max;\n};","keywords":"LeetCode 565, #565 - Array Nesting, Medium, 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/array-nesting |
| 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/array-nesting/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0565-array-nesting.js |
| Array | https://leetcodejavascript.com/tags/array |
| Depth-First Search | https://leetcodejavascript.com/tags/depth-first-search |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow