How can I reduce time complexity on this algorithm?

I have this exercise and the goal is to solve it with complexity less than O(n^2). You have an array with length N filled with event probabilities. Create another array in which for each element i calculate the probability of all event to happen until the position i. I have coded this O(n^2) solution. Any… Read More How can I reduce time complexity on this algorithm?

Complexity between if-else, switch and regex

I’m going to optimize javascript code in which I seen old code is like below, var emcont = $(‘#emcont’).val(); numericMatch = emcont.match(/\d/g); if (numericMatch == null) { isValid = false; $(‘#msg_emcont’).html(getMessage(‘msg_emcont’)).show(); } else if (emcont.length != 14) { isValid = false; $(‘#msg_emcont’).html(getMessage(‘msg_emcont’)).show(); } else if (numericMatch.length && numericMatch.length != 10) { isValid = false; $(‘#msg_emcont’).html(getMessage(‘msg_emcont’)).show();… Read More Complexity between if-else, switch and regex