Skip to content
Advertisement

Tag: algorithm

JavaScript: return all contiguous subarrays whose sum equals K

This is a variant of this leetcode question, but instead of returning the count, we want to return the actual contiguous sub arrays. For example, if num = [1,2,4,7] k=7 the returned value should be [[1,2,4],[7]] . I used a hashmap to store the cumulative sum up to all the indices possible along with the number of times the same

Find the point where maximum intervals overlap for certain interval length

I’m trying to maximize attendance to a event given a list of busy times for each person. The event can be scheduled anytime between a certain date and hours (Ex. March 1st to March 8th from 9-5) and that attendance is maximized. So far I’ve tried using a sliding window approach, and a counting approach described here (https://www.geeksforgeeks.org/find-the-point-where-maximum-intervals-overlap/) however I

CodeSignal reverseParentheses Failing one case

Write a function that reverses characters in (possibly nested) parentheses in the input string. Input strings will always be well-formed with matching ()s. For inputString = “(bar)”, the output should be reverseInParentheses(inputString) = “rab”; For inputString = “foo(bar)baz”, the output should be reverseInParentheses(inputString) = “foorabbaz”; For inputString = “foo(bar(baz))blim”, the output should be reverseInParentheses(inputString) = “foobazrabblim”. [input] string inputString A

Why is this recursion example giving me an infinite loop?

This is driving me insane. Here is the code : Why is this giving me an infinite loop when it’s supposed to print ‘laugh’ 10 times? Answer Like other answers said, each laugh() created a new local counter. The most appropriate recursive method here is to pass the counter as an argument: This is a pure function approach, reducing the

Advertisement