'2017/06/08'에 해당되는 글 5건

  1. 2017.06.08 12. sortByHeight 1
  2. 2017.06.08 11. isLucky 1
  3. 2017.06.08 10. commonCharacterCount 1
  4. 2017.06.08 9. allLongestStrings 1
  5. 2017.06.08 8. matrixElementsSum 1
알고리즘(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