If I remove one element from an array using splice() like so:  arr.splice(i, 1);   Will this be O(n) in the worst case because it shifts all the elements after i? Or is it constant time, with some linked list magic underneath?...
What's the big O for JavaScript's array access when used as a hash?  For example,  var x= []; for(var i=0; i<100000; i++){    x[i.toString()+'a'] = 123; // using string to illustrate x[alpha] } alert(x['9999a']); // linear...
Example:  var string = "abcde"; var array = string.split(""); // array = ["a", "b", "c", "d", "e"]   What is the amortized running time of this split function? Also, how do I view source code of...
My function should return the missing element in a given array range. So i first sorted the array and checked if the difference between i and i+1 is not equal to 1, i'm returning the missing element.  // Given an array A such that: // A[0] = 2 //...
I have a problem which requires a string to be transformed into another one by appending copies of its' initial value to itself. The problem allows to remove single characters at some places.  Explanation  let x = "abba"; // First string...
I have the memoization fibonacci code and I am having trouble figuring out what the time complexity is of it:  function fibMemo(index, cache) {   cache = cache || [];   if (cache[index]) return cache[index];   else {     if (index < 3) return 1;...
I am having trouble understanding how the following solution is O(1) space and not O(n) space.  The coding challenge is as follows:  Write a solution that only iterates over the string once and uses O(1) additional memory, since this is what you woul...
I'm using _.uniqWith in Lodash to remove duplicate objects from an array of ~6,000 objects:  let uniqColors = _.uniqWith(colorCollection, _.isEqual);   Where a sample object in the array looks like:  {   r: 122,   g: 44,   b: 216 }   It takes abo...
What is the time complexity of Map.prototype.get if properties of map are objects?  const o1 = {v: 1}; const o2 = {v: 2}; const m = new Map();  m.set(o1, 'o1'); m.set(o2, 'o2');  m.get(o1) // Time complexity O(1)? m.get(o2) // Time co...
So let's say I had a program that looked like this:  var foo = 10;  for(var i = 0; i < foo; i++){     console.log('first loop'); }  for(var j = 0 j < foo; j++){     console.log('second loop'); }   Now, from what I understand...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.