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...
I have two object literals like so:  var firstObject = {     x: 0,     y: 1,     z: 2,      a: 10,     b: 20,     e: 30 }  var secondObject = {     x: 0,     y: 1,     z: 2,      a: 10,     c: 20,     d: 30 }   I want to get the intersection of the k...
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...
I was studying big O notation for a technical interview and then I realized that javascript's indexOf method may have a time complexity of O(N) as it traverses through each element of an array and returns the index where its found.   We also know...
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 //...
Mozilla's website clearly describes hasOwnProperty() and the in operator.  However, it does not give any implementation details in regards to their efficiencies.  I would suspect they'd be O(1) (constant time) but would love to see any refere...
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...
For an example I have below mentioned input and output for function reverseWords()  It's a simple example but this will help me understand. How I will write a function which is In O(1) space for below request ?   // var input = ['H', '...
one month ago I've been interviewed by some google PTO members. One of the questions was:  Invert a string recursively in js and explain the running time by big O notation  this was my solution:  function invert(s){     return (s.length > 1) ?...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.