AlmostIncreasingSequence | CodeFights Intro Algorithm JavaScript Solution and Breakdown



AlmostIncreasingSequence | CodeFights Intro Algorithm JavaScript Solution and Breakdown
Support our Community:
-Donate:
-Patreon:
-Code, Tech and Caffeine Facebook Group:
-Discord:
– Looking for a a Bootcamp check out DevMountain’s program where housing is included with the tuition:

Tutoring, Mentoring and Course Walkthroughs available:

Thank you to my Patreon Supporters Below:
-Check out youtube.com/user/cardinalslinkyband

Support me and visit my store at:

Internship, Part-Time, & Full time work for college students and recent grads:

Fan funding goes towards buying the equipment necessary to deliver 4k videos, 4k webcam, and a high quality microphone better audio. Any support is very appreciated!

My channel is here for aspiring programmers to learn easier and help debug any issues from the many great free resources available on the web.

Check out my other videos going over HTML, CSS, Ruby, Ruby on Rails, Java, JavaScript, Python, PHP, SQL, Command Line, BootStrap, jQuery, and WordPress from CodeCademy, CodeCombat, FreeCodecamp and more!

-~-~~-~~~-~~-~-
Please watch: “How I Became a Developer | My Developer Journey of the Last 3 Years | Ask a Dev”

-~-~~-~~~-~~-~-

Nguồn:https://cinausp.org/

19 thoughts on “AlmostIncreasingSequence | CodeFights Intro Algorithm JavaScript Solution and Breakdown

  1. Maybe JavaScript is much different from Java, but just by looking at the code, you sure thing get out of bounds exceptions.

  2. Nice one;
    Couldn't put down a good logic statement to solve the problem;
    First few lines of the program outline seem to be a little bit the same;
    Nice one;

  3. I'm feeling bad, i've create all this code that not passed, and the solution is more simple than i think

    function(sequence){
    for(x=0; x<sequence.length; x++){
    var removedNum = sequence.splice(x, 1);
    console.log("New array: " + sequence.toString());
    console.log("Removed number: " + removedNum.toString());
    var count = 0;
    for(z=0; z<sequence.length-1; z++){
    if(parseInt(sequence[z]) >= parseInt(sequence[z+1])){
    count++;
    }
    }
    console.log("Count: " + cont);
    if(cont==0){
    return true;
    }
    sequence.splice(x,0,parseInt(removedNum));
    console.log(sequence.toString());
    }
    return false;
    }

  4. here is my code for this particular problem, this code works with all the test case but it exceeded the execution time limit. kindly tell me how to reduce it

    ps: this code is in python

    def almostIncreasingSequence(sequence):
    x=sequence
    y=x[:]
    state=[]
    state_list=[]

    for i in range(len(x)):
    y=x[:]
    del y[i]
    for j in range(len(y)):
    if j==len(y)-1:
    pass
    elif y[j] < y[j+1]:
    state.append(True)
    else:
    state.append(False)
    state_list.append(state)
    state=[]

    for i in state_list:
    if False not in i:
    return True
    return False

    your output will be most beneficial

  5. Solved this problem under 10 mins only to find that my program is not optimized enough to pass the time constraint checks in the last two tests. It almost took a day for me to again resolve it.

  6. instead of checking if it's sorted….why not just sort it by default….it's takes the same amount of code…am I wrong?

  7. I used a prototype 🙂

    let arr = [0,1,2,3,4,5,4];

    Array.prototype.inc = function(i) {
    return this[i] <= this[i+1];
    }

    function isAlmostInc(arr) {
    var falseCount = 0;
    for (let i = 0; i < arr.length -1; i++) {
    if (arr.inc(i) === false) falseCount++;
    }
    return falseCount < 2;
    }

    console.log(isAlmostInc(arr));

  8. This problem got me, but I kept at it. my logic might be time consuming but hey I passed all the tests and that is what matters

Leave a Reply

Your email address will not be published. Required fields are marked *