'알고리즘(CF)'에 해당되는 글 23건

  1. 2017.06.20 22. avoidObstacles 1
  2. 2017.06.19 21. isIPv4Address 1
  3. 2017.06.18 20. arrayMaximalAdjacentDifference 1
  4. 2017.06.18 19. areEquallyStrong 1
  5. 2017.06.17 18. palindromeRearranging 1
  6. 2017.06.17 17. arrayChange 1
  7. 2017.06.17 16. areSimilar 1
  8. 2017.06.17 15. addBorder 1
  9. 2017.06.17 14. alternatingSums 1
  10. 2017.06.17 13. reverseParentheses 1
알고리즘(CF)2017. 6. 20. 20:27

You are given an array of integers representing coordinates of obstacles situated on a straight line.

Assume that you are jumping from the point with coordinate 0 to the right. You are allowed only to make jumps of the same length represented by some integer.

Find the minimal length of the jump enough to avoid all the obstacles.




Example


For inputArray = [5, 3, 6, 7, 9], the output should be
avoidObstacles(inputArray) = 4.

Check out the image below for better understanding:




Code


function avoidObstacles(inputArray) {


}


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

21. isIPv4Address  (1) 2017.06.19
20. arrayMaximalAdjacentDifference  (1) 2017.06.18
19. areEquallyStrong  (1) 2017.06.18
18. palindromeRearranging  (1) 2017.06.17
17. arrayChange  (1) 2017.06.17
Posted by EL2A
알고리즘(CF)2017. 6. 19. 21:54

An IP address is a numerical label assigned to each device (e.g., computer, printer) participating in a computer network that uses the Internet Protocol for communication. There are two versions of the Internet protocol, and thus two versions of addresses. One of them is the IPv4 address.

IPv4 addresses are represented in dot-decimal notation, which consists of four decimal numbers, each ranging from 0 to 255, separated by dots, e.g., 172.16.254.1.

Given a string, find out if it satisfies the IPv4 address naming rules.




Example


  • For inputString = "172.16.254.1", the output should be
    isIPv4Address(inputString) = true;

  • For inputString = "172.316.254.1", the output should be
    isIPv4Address(inputString) = false.

    316 is not in range [0, 255].

  • For inputString = ".254.255.0", the output should be
    isIPv4Address(inputString) = false.

    There is no first number.





Code


function isIPv4Address(inputString) {

   

}

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

22. avoidObstacles  (1) 2017.06.20
20. arrayMaximalAdjacentDifference  (1) 2017.06.18
19. areEquallyStrong  (1) 2017.06.18
18. palindromeRearranging  (1) 2017.06.17
17. arrayChange  (1) 2017.06.17
Posted by EL2A
알고리즘(CF)2017. 6. 18. 10:43

Given an array of integers, find the maximal absolute difference between any two of its adjacent elements.




Example

For inputArray = [2, 4, 1, 0], the output should be
arrayMaximalAdjacentDifference(inputArray) = 3.




Code

function arrayMaximalAdjacentDifference(inputArray) {

    

}

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

22. avoidObstacles  (1) 2017.06.20
21. isIPv4Address  (1) 2017.06.19
19. areEquallyStrong  (1) 2017.06.18
18. palindromeRearranging  (1) 2017.06.17
17. arrayChange  (1) 2017.06.17
Posted by EL2A
알고리즘(CF)2017. 6. 18. 10:42

Call two arms equally strong if the heaviest weights they each are able to lift are equal.

Call two people equally strong if their strongest arms are equally strong (the strongest arm can be both the right and the left), and so are their weakest arms.

Given your and your friend's arms' lifting capabilities find out if you two are equally strong.




Example

  • For yourLeft = 10yourRight = 15friendsLeft = 15 and friendsRight = 10, the output should be
    areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight) = true;
  • For yourLeft = 15yourRight = 10friendsLeft = 15 and friendsRight = 10, the output should be
    areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight) = true;
  • For yourLeft = 15yourRight = 10friendsLeft = 15 and friendsRight = 9, the output should be
    areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight) = false.





Code

function areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight) {

  

}


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

21. isIPv4Address  (1) 2017.06.19
20. arrayMaximalAdjacentDifference  (1) 2017.06.18
18. palindromeRearranging  (1) 2017.06.17
17. arrayChange  (1) 2017.06.17
16. areSimilar  (1) 2017.06.17
Posted by EL2A
알고리즘(CF)2017. 6. 17. 21:21

Given a string, find out if its characters can be rearranged to form a palindrome.




Example

For inputString = "aabb", the output should be
palindromeRearranging(inputString) = true.

We can rearrange "aabb" to make "abba", which is a palindrome.




Code

function palindromeRearranging(inputString) {

   

}

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

20. arrayMaximalAdjacentDifference  (1) 2017.06.18
19. areEquallyStrong  (1) 2017.06.18
17. arrayChange  (1) 2017.06.17
16. areSimilar  (1) 2017.06.17
15. addBorder  (1) 2017.06.17
Posted by EL2A
알고리즘(CF)2017. 6. 17. 21:20

You are given an array of integers. On each move you are allowed to increase exactly one of its element by one. Find the minimal number of moves required to obtain a strictly increasing sequence from the input.




Example

For inputArray = [1, 1, 1], the output should be
arrayChange(inputArray) = 3.




Code

function arrayChange(inputArray) {

   

}

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

19. areEquallyStrong  (1) 2017.06.18
18. palindromeRearranging  (1) 2017.06.17
16. areSimilar  (1) 2017.06.17
15. addBorder  (1) 2017.06.17
14. alternatingSums  (1) 2017.06.17
Posted by EL2A
알고리즘(CF)2017. 6. 17. 21:19

wo arrays are called similar if one can be obtained from another by swapping at most one pair of elements in one of the arrays.

Given two arrays a and b, check whether they are similar.




Example

  • For a = [1, 2, 3] and b = [1, 2, 3], the output should be
    areSimilar(a, b) = true.

    The arrays are equal, no need to swap any elements.

  • For a = [1, 2, 3] and b = [2, 1, 3], the output should be
    areSimilar(a, b) = true.

    We can obtain b from a by swapping 2 and 1 in b.

  • For a = [1, 2, 2] and b = [2, 1, 1], the output should be
    areSimilar(a, b) = false.

    Any swap of any two elements either in a or in b won't make a and b equal.





Code

function areSimilar(a, b) {

    

}

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

18. palindromeRearranging  (1) 2017.06.17
17. arrayChange  (1) 2017.06.17
15. addBorder  (1) 2017.06.17
14. alternatingSums  (1) 2017.06.17
13. reverseParentheses  (1) 2017.06.17
Posted by EL2A
알고리즘(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