본문 바로가기

알고리즘117

[HackerRank] Breaking the Records (PYTHON) 문제 링크 : https://www.hackerrank.com/challenges/breaking-best-and-worst-records/problem Breaking the Records | HackerRank Given an array of Maria's basketball scores all season, determine the number of times she breaks her best and worst records. www.hackerrank.com 최고기록을 갱신 시마다 업데이트 시켜주는 것이 중요하다는 것을 알게 되었습니다. def breakingRecords(scores): # Write your code here win_cnt, lose_cnt = 0,0 breaking_win,.. 2021. 11. 1.
[HackerRank] Divisible Sum Pairs (PYTHON) 문제 링크 : https://www.hackerrank.com/challenges/divisible-sum-pairs/problem Divisible Sum Pairs | HackerRank Count the number of pairs in an array having sums that are evenly divisible by a given number. www.hackerrank.com O(n²) 의 시간복잡도를 가진다. def divisibleSumPairs(n, k, ar): # Write your code here cnt = 0 for i in range(len(ar)): for j in range(i+1,len(ar)): if (ar[i] + ar[j]) % k == 0: cnt += 1 r.. 2021. 11. 1.
[HackerRank] Pairs (PYTHON) 문제 Given an array of integers and a target value, determine the number of pairs of array elements that have a difference equal to the target value.링크 Example There are three values that differ by : , , and . Return . Function Description Complete the pairs function below. pairs has the following parameter(s): int k: an integer, the target difference int arr[n]: an array of integers 입력 The first .. 2021. 10. 29.
[프로그래머스] 타겟 넘버 - BFS 타겟 넘버 문제 설명 n개의 음이 아닌 정수가 있습니다. 이 수를 적절히 더하거나 빼서 타겟 넘버를 만들려고 합니다. 예를 들어 [1, 1, 1, 1, 1]로 숫자 3을 만들려면 다음 다섯 방법을 쓸 수 있습니다. -1+1+1+1+1 = 3 +1-1+1+1+1 = 3 +1+1-1+1+1 = 3 +1+1+1-1+1 = 3 +1+1+1+1-1 = 3 사용할 수 있는 숫자가 담긴 배열 numbers, 타겟 넘버 target이 매개변수로 주어질 때 숫자를 적절히 더하고 빼서 타겟 넘버를 만드는 방법의 수를 return 하도록 solution 함수를 작성해주세요. 제한사항 주어지는 숫자의 개수는 2개 이상 20개 이하입니다. 각 숫자는 1 이상 50 이하인 자연수입니다. 타겟 넘버는 1 이상 1000 이하인 자연.. 2021. 9. 20.