'2017/06'에 해당되는 글 47건

  1. 2017.06.17 15. addBorder 1
  2. 2017.06.17 14. alternatingSums 1
  3. 2017.06.17 13. reverseParentheses 1
  4. 2017.06.08 12. sortByHeight 1
  5. 2017.06.08 11. isLucky 1
  6. 2017.06.08 10. commonCharacterCount 1
  7. 2017.06.08 9. allLongestStrings 1
  8. 2017.06.08 8. matrixElementsSum 1
  9. 2017.06.07 7. almostIncreasingSequence 1
  10. 2017.06.07 6. make Array Consecutive2 1
알고리즘(CF)2017. 6. 17. 21:18


Given a rectangular matrix of characters, add a border of asterisks(*) to it.




Example

For

picture = ["abc",
           "ded"]

the output should be

addBorder(picture) = ["*****",
                      "*abc*",
                      "*ded*",
                      "*****"]





Code

function addBorder(picture) {

   

}

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

17. arrayChange  (1) 2017.06.17
16. areSimilar  (1) 2017.06.17
14. alternatingSums  (1) 2017.06.17
13. reverseParentheses  (1) 2017.06.17
12. sortByHeight  (1) 2017.06.08
Posted by EL2A
알고리즘(CF)2017. 6. 17. 21:16

Several people are standing in a row and need to be divided into two teams. The first person goes into team 1, the second goes into team 2, the third goes into team 1 again, the fourth into team 2, and so on.

You are given an array of positive integers - the weights of the people. Return an array of two integers, where the first element is the total weight of team 1, and the second element is the total weight of team 2 after the division is complete.




Example

For a = [50, 60, 60, 45, 70], the output should be
alternatingSums(a) = [180, 105].




Code

function alternatingSums(a) {

    

}

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

16. areSimilar  (1) 2017.06.17
15. addBorder  (1) 2017.06.17
13. reverseParentheses  (1) 2017.06.17
12. sortByHeight  (1) 2017.06.08
11. isLucky  (1) 2017.06.08
Posted by EL2A
알고리즘(CF)2017. 6. 17. 21:15

You have a string s that consists of English letters, punctuation marks, whitespace characters, and brackets. It is guaranteed that the parentheses in s form a regular bracket sequence.

Your task is to reverse the strings contained in each pair of matching parentheses, starting from the innermost pair. The results string should not contain any parentheses.




Example

For string s = "a(bc)de", the output should be
reverseParentheses(s) = "acbde".




Code

function reverseParentheses(s) {


}

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

15. addBorder  (1) 2017.06.17
14. alternatingSums  (1) 2017.06.17
12. sortByHeight  (1) 2017.06.08
11. isLucky  (1) 2017.06.08
10. commonCharacterCount  (1) 2017.06.08
Posted by EL2A
알고리즘(CF)2017. 6. 8. 19:53

Some people are standing in a row in a park. There are trees between them which cannot be moved. Your task is to rearrange the people by their heights in a non-descending order without moving the trees.




Example


For a = [-1, 150, 190, 170, -1, -1, 160, 180], the output should be
sortByHeight(a) = [-1, 150, 160, 170, -1, -1, 180, 190].





Code


function sortByHeight(a) {


}

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

14. alternatingSums  (1) 2017.06.17
13. reverseParentheses  (1) 2017.06.17
11. isLucky  (1) 2017.06.08
10. commonCharacterCount  (1) 2017.06.08
9. allLongestStrings  (1) 2017.06.08
Posted by EL2A
알고리즘(CF)2017. 6. 8. 19:52

Ticket numbers usually consist of an even number of digits. A ticket number is considered lucky if the sum of the first half of the digits is equal to the sum of the second half.

Given a ticket number n, determine if it's lucky or not.




Example

  • For n = 1230, the output should be
    isLucky(n) = true;
  • For n = 239017, the output should be
    isLucky(n) = false.




Code


function isLucky(n) {


}

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

13. reverseParentheses  (1) 2017.06.17
12. sortByHeight  (1) 2017.06.08
10. commonCharacterCount  (1) 2017.06.08
9. allLongestStrings  (1) 2017.06.08
8. matrixElementsSum  (1) 2017.06.08
Posted by EL2A
알고리즘(CF)2017. 6. 8. 19:51

Given two strings, find the number of common characters between them.





Example


For s1 = "aabcc" and s2 = "adcaa", the output should be
commonCharacterCount(s1, s2) = 3.

Strings have 3 common characters - 2 "a"s and 1 "c".





Code


function commonCharacterCount(s1, s2) {


}

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

12. sortByHeight  (1) 2017.06.08
11. isLucky  (1) 2017.06.08
9. allLongestStrings  (1) 2017.06.08
8. matrixElementsSum  (1) 2017.06.08
7. almostIncreasingSequence  (1) 2017.06.07
Posted by EL2A
알고리즘(CF)2017. 6. 8. 19:49

Given an array of strings, return another array containing all of its longest strings.

가장 긴 문자열을 포함하는 배열들을 반환하라




Example


For inputArray = ["aba", "aa", "ad", "vcd", "aba"], the output should be
allLongestStrings(inputArray) = ["aba", "vcd", "aba"].





Code


function allLongestStrings(inputArray) {


}

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

11. isLucky  (1) 2017.06.08
10. commonCharacterCount  (1) 2017.06.08
8. matrixElementsSum  (1) 2017.06.08
7. almostIncreasingSequence  (1) 2017.06.07
6. make Array Consecutive2  (1) 2017.06.07
Posted by EL2A
알고리즘(CF)2017. 6. 8. 19:44

After becoming famous, CodeBots decided to move to a new building and live together. The building is represented by a rectangular matrix of rooms, each cell containing an integer - the price of the room. Some rooms are free (their cost is 0), but that's probably because they are haunted, so all the bots are afraid of them. That is why any room that is free or is located anywhere below a free room in the same column is not considered suitable for the bots.

Help the bots calculate the total price of all the rooms that are suitable for them.




Example


For

matrix = [[0, 1, 1, 2], 
          [0, 5, 0, 0], 
          [2, 0, 3, 3]]

the output should be
matrixElementsSum(matrix) = 9.


Here's the rooms matrix with unsuitable rooms marked with 'x':

[[x, 1, 1, 2], 
 [x, 5, x, x], 
 [x, x, x, x]]

Thus, the answer is 1 + 5 + 1 + 2 = 9.




Code


int matrixElementsSum(int[][] matrix) {


}


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

10. commonCharacterCount  (1) 2017.06.08
9. allLongestStrings  (1) 2017.06.08
7. almostIncreasingSequence  (1) 2017.06.07
6. make Array Consecutive2  (1) 2017.06.07
5. shapeArea  (1) 2017.06.07
Posted by EL2A
알고리즘(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