I want to write a function that receives two sequences: A and B and returns sequence C which should contain all elements from A (in order) except those that are present in B p times. For example sequences A=[2,3,9,2,5,1,3,7,10] B=[2,1,3,4,3,10,6,6,1,7,10,10,10] Should return C=[2,9,2,5,7,10] When p = 2 I wrote it like this: But is there a better way to make

# Tag: time-complexity

## What is the time complexity of object spread operator in Javascript?

I found that there are some QAs about spread operator time complexity but those are all for array. Is the spread operator time complexity same for object? What is the time complexity of the above statement if the key count of b is N? is it O(N)? Answer It’s O(n). Object spread iterates through all enumerable own properties and assigns

## 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

## Object.entries() time complexity

Does anyone know the complexity of Object.entries() in Javascript? Based on this question I’d guess at maybe O(n) as well if it’s implemented by obtaining the keys and values as arrays then zipping them together? Answer (V8 developer here.) Short answer: yes, the complexity of Object.entries() is O(n) in most cases. For large objects (thousands of properties), it is O(n

## Constant space, one pass, daily coding problem

This is the Daily Coding Problem: “Given a singly linked list and an integer k, remove the kth last element from the list. k is guaranteed to be smaller than the length of the list. The list is very long, so making more than one pass is prohibitively expensive. Do this in constant space and in one pass.” … Here