LeetCode: Form Array By Concatenating Subarrays Of Another Array Solution
1const arrayEqual = (a, b) =>2 a.length === b.length && a.every((el, i) => el === b[i])34/**5 * @param {number[][]} groups6 * @param {number[]} nums7 * @return {boolean}8 */9var canChoose = function (groups, nums) {10 let i = 01112 groupsLoop: for (const group of groups) {13 for (let j = i; j < nums.length; j++) {14 if (arrayEqual(nums.slice(j, j + group.length), group)) {15 i = j + group.length16 continue groupsLoop17 }18 }19 return false20 }2122 return true23}
Comments
Loading comments...
Tags
leetcode
array
greedy
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.