I came across an interesting question in Code Signal. "Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array." It is strictly increasing if every element in the array is greater than its successor. For a strictly increasing sequence we can check for each element whether it is greater than the next. In that case we can come to a conclusion that this sequence is not strictly increasing. If every element is greater than the successor we get to know it is a strictly increasing. For worst case(The sequence is strictly increasing), the algorithmic complexity is O(n). If we use similar approach for the question, we have to remove each element and pass the sequence to the above function. So for n elements, we use a fun
Comments
Post a Comment