'2017/06/07'에 해당되는 글 8건

  1. 2017.06.07 7. almostIncreasingSequence 1
  2. 2017.06.07 6. make Array Consecutive2 1
  3. 2017.06.07 5. shapeArea 1
  4. 2017.06.07 4. adjacentElementsProduct 1
  5. 2017.06.07 3. checkPalindrome 1
  6. 2017.06.07 2. centuryFromYear 1
  7. 2017.06.07 1. add 1
  8. 2017.06.07 https://codefights.com
알고리즘(CF)2017. 6. 7. 21:52

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 be
    almostIncreasingSequence(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 be
    almostIncreasingSequence(sequence) = true.

    You can remove 3 from the array to get the strictly increasing sequence [1, 2]. Alternately, you can remove 2 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
Posted by EL2A
알고리즘(CF)2017. 6. 7. 21:46

Ratiorg got statues of different sizes as a present from CodeMaster for his birthday, each statue having an non-negative integer size. Since he likes to make things perfect, he wants to arrange them from smallest to largest so that each statue will be bigger than the previous one exactly by 1. He may need some additional statues to be able to accomplish that. Help him figure out the minimum number of additional statues needed.

주어진 값 중에서 가장 큰 수의 값과 가장 작은 수의 값 사이에 없는 수의 개수를 구하여라.




Example


For statues = [6, 2, 3, 8], the output should be
makeArrayConsecutive2(statues) = 3.

Ratiorg needs statues of sizes 45 and 7.


Input: [5, 4, 6]

Expected Output: 0


Input: [6, 3]

Expected Output: 2




Code


int makeArrayConsecutive2(int[] statues) {
2


}


'알고리즘(CF)' 카테고리의 다른 글

8. matrixElementsSum  (1) 2017.06.08
7. almostIncreasingSequence  (1) 2017.06.07
5. shapeArea  (1) 2017.06.07
4. adjacentElementsProduct  (1) 2017.06.07
3. checkPalindrome  (1) 2017.06.07
Posted by EL2A
알고리즘(CF)2017. 6. 7. 21:42

Below we will define an n-interesting polygon. Your task is to find the area of a polygon for a given n.

1-interesting polygon is just a square with a side of length 1. An n-interesting polygon is obtained by taking the n - 1-interesting polygon and appending 1-interesting polygons to its rim, side by side. You can see the 1-, 2-, 3- and 4-interesting polygons in the picture below.



Example


  • For n = 2, the output should be
    shapeArea(n) = 5;
  • For n = 3, the output should be
    shapeArea(n) = 13.



Code


int shapeArea(int n) {
2

 

3
}


'알고리즘(CF)' 카테고리의 다른 글

7. almostIncreasingSequence  (1) 2017.06.07
6. make Array Consecutive2  (1) 2017.06.07
4. adjacentElementsProduct  (1) 2017.06.07
3. checkPalindrome  (1) 2017.06.07
2. centuryFromYear  (1) 2017.06.07
Posted by EL2A
알고리즘(CF)2017. 6. 7. 21:36

Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.

일련의 정수를 확인하여, 가장 큰 수와 인접한 요소를 찾아 곱한 값을 구하라



Example


For inputArray = [3, 6, -2, -5, 7, 3], the output should be
adjacentElementsProduct(inputArray) = 21.

7 and 3 produce the largest product.


inputArray: [-1, -2]

Expected Output:2


inputArray: [5, 1, 2, 3, 1, 4]

Expected Output: 6


inputArray: [9, 5, 10, 2, 24, -1, -48]

Expected Output: 50




Code


int adjacentElementsProduct(int[] inputArray) {
2

 

9
}


'알고리즘(CF)' 카테고리의 다른 글

6. make Array Consecutive2  (1) 2017.06.07
5. shapeArea  (1) 2017.06.07
3. checkPalindrome  (1) 2017.06.07
2. centuryFromYear  (1) 2017.06.07
1. add  (1) 2017.06.07
Posted by EL2A
알고리즘(CF)2017. 6. 7. 21:28

Given the string, check if it is a palindrome.

해당 문자열을 고려하여 회문인지 확인하라



Example


  • For inputString = "aabaa", the output should be
    checkPalindrome(inputString) = true;
  • For inputString = "abac", the output should be
    checkPalindrome(inputString) = false;
  • For inputString = "a", the output should be
    checkPalindrome(inputString) = true.


Code


boolean checkPalindrome(String inputString) {
2

 

12
}


'알고리즘(CF)' 카테고리의 다른 글

5. shapeArea  (1) 2017.06.07
4. adjacentElementsProduct  (1) 2017.06.07
2. centuryFromYear  (1) 2017.06.07
1. add  (1) 2017.06.07
https://codefights.com  (0) 2017.06.07
Posted by EL2A
알고리즘(CF)2017. 6. 7. 21:21

Given a year, return the century it is in. The first century spans from the year 1 up to and including the year 100, the second - from the year 101 up to and including the year 200, etc.

년도를 넣으면 해당세기를 구하라



Example


  • For year = 1905, the output should be
    centuryFromYear(year) = 20;
  • For year = 1700, the output should be
    centuryFromYear(year) = 17.



Code


int centuryFromYear(int year) {
2

 

3
}


'알고리즘(CF)' 카테고리의 다른 글

5. shapeArea  (1) 2017.06.07
4. adjacentElementsProduct  (1) 2017.06.07
3. checkPalindrome  (1) 2017.06.07
1. add  (1) 2017.06.07
https://codefights.com  (0) 2017.06.07
Posted by EL2A
알고리즘(CF)2017. 6. 7. 21:08

Write a function that returns the sum of two numbers.

두 숫자의 합을 반환하는 함수를 작성합니다.



Example


For param1 = 1 and param2 = 2, the output should be
add(param1, param2) = 3.




Code


1
int add(int param1, int param2) {
2

 

3
}


'알고리즘(CF)' 카테고리의 다른 글

5. shapeArea  (1) 2017.06.07
4. adjacentElementsProduct  (1) 2017.06.07
3. checkPalindrome  (1) 2017.06.07
2. centuryFromYear  (1) 2017.06.07
https://codefights.com  (0) 2017.06.07
Posted by EL2A
알고리즘(CF)2017. 6. 7. 21:06



현재 카테고리에서 제공되는 문제 소스의 출처는 아래의 사이트에 있으며 정답은 코멘트에 있습니다.


https://codefights.com

'알고리즘(CF)' 카테고리의 다른 글

5. shapeArea  (1) 2017.06.07
4. adjacentElementsProduct  (1) 2017.06.07
3. checkPalindrome  (1) 2017.06.07
2. centuryFromYear  (1) 2017.06.07
1. add  (1) 2017.06.07
Posted by EL2A