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.
제공된 배열의 일련번호에서 두개의 요소를 제거할 수 있다. 일련번호가 엄격하게 숫자가 증가하는지 확인하라
Example
For
sequence = [1, 3, 2, 1]
, the output should bealmostIncreasingSequence(sequence) = false
;There is no one element in this array that can be removed in order to get a strictly increasing sequence.
For
sequence = [1, 3, 2]
, the output should bealmostIncreasingSequence(sequence) = true
.You can remove
3
from the array to get the strictly increasing sequence[1, 2]
. Alternately, you can remove2
to get the strictly increasing sequence[1, 3]
.
Input: [1, 3, 2]
Expected Output: true
Input: [1, 2, 1, 2]
Expected Output: false
Input: [1, 4, 10, 4, 2]
Expected Output: false
Input: [10, 1, 2, 3, 4, 5]
Expected Output: true
Input: [1, 1, 1, 2, 3]
Expected Output: false
Input: [0, -2, 5, 6]
Expected Output: true
Input: [1, 2, 3, 4, 5, 3, 5, 6]
Expected Output: false
Input: [40, 50, 60, 10, 20, 30]
Expected Output: false
Input: [1, 1]
Expected Output: true
Input: [10, 1, 2, 3, 4, 5, 6, 1]
Expected Output: false
Input: [1, 2, 3, 4, 3, 6]
Expected Output: true
Input: [1, 2, 3, 4, 99, 5, 6]
Expected Output: true
Input: [123, -17, -5, 1, 2, 3, 12, 43, 45]
Expected Output: true
Input: [3, 5, 67, 98, 3]
Expected Output: true
Code
boolean almostIncreasingSequence(int[] sequence) {
2
}
문제의 이해도 어려웠지만 해결은 더 어려웠다.
'알고리즘(CF)' 카테고리의 다른 글
9. allLongestStrings (1) | 2017.06.08 |
---|---|
8. matrixElementsSum (1) | 2017.06.08 |
6. make Array Consecutive2 (1) | 2017.06.07 |
5. shapeArea (1) | 2017.06.07 |
4. adjacentElementsProduct (1) | 2017.06.07 |