Coding
-
[HackerRank] Mini-Max Sum c++Coding Test/HackerRank 2022. 7. 16. 23:06
problem Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers. example arr = [1,3,5,7,9] The minimum sum is 1 + 3 + 5 + 7 = 16 and the maximum sum is 3 + 5 + 7 +9 = 24. The function prints 16 24 constraints 1
-
[HackerRank] Staircase c++Coding Test/HackerRank 2022. 7. 16. 22:31
problem This is a staircase of size n =4 : # ## ### #### Its base and height are both equal to n. It is drawn using # symbols and spaces. The last line is not preceded by any spaces. Write a program that prints a staircase of size n. sample input 6 sample output # ## ### #### ##### ###### explanation The staircase is right-aligned, composed of # symbols and spaces, and has a height and width of ..
-
[HackerRank] Plus Minus c++Coding Test/HackerRank 2022. 7. 16. 21:49
problem Given an array of integers, calculate the ratios of its elements that are positive, negative, and zero. Print the decimal value of each fraction on a new line with 6 places after the decimal. example arr = [1,1,0,-1,-1] There are n = 5 elements, two positive, two negative and one zero. Their ratios are 2/5 = 0.400000, 2/5 = 0.400000 and 1/5 = 0.200000. Results are printed as: 0.400000 0...
-
[HackerRank] Diagonal Difference c++Coding Test/HackerRank 2022. 7. 16. 20:58
problem Given a square matrix, calculate the absolute difference between the sums of its diagonals. For example, the square matrix is shown below: 1 2 3 4 5 6 9 8 9 The left-to-right diagonal = 1 + 5 + 9. The right to left diagonal = 3 +5 +9. Their absolute difference is |15-17| = 2. sample input 3 11 2 4 4 5 6 10 8 -12 output 15 solution 왼쪽방향 대각선, 오른쪽 방향 대각선의 원소들의 합을 구한뒤 둘의 차를 구하는 문제이다. sample ..
-
[HackerRank] A Very Bing Sum c++Coding Test/HackerRank 2022. 7. 16. 20:32
Problem In this challenge, you are required to calculate and print the sum of the elements in an array, keeping in mind that some of those integers may be quite large. Function Description Complete the aVeryBigSum function in the editor below. It must return the sum of all array elements. aVeryBigSum has the following parameter(s): - int ar[n]: an array of integers . sample input 5 1000000001 10..
-
[codility] BinaryGap c++Coding Test/codility 2022. 4. 8. 11:39
문제 설명 10진수 N을 2진수로 바꾼 후, 1과 1 사이에 존재하는 0의 개수를 구하는 문제이다. ex, 1001 -> length : 2 1000010001 -> length : 4 , 3 -> 이 때는 더 큰 수를 return 한다 -> 4 10100 -> length : 1 100000 -> length : 0 -> 1이 하나만 있기 때문에 1과 1사이의 0이 없다. 문제 풀이 1. string 에 2진수 변환 저장 2. 1검사해서 index vector에 저장 3. index vector size가 1이라면 1이 한개라는 뜻이므로 return 0 4. index vector 에 1의 index가 저장되어 있기에 각 index에 빼기 연산을 하여 Binary Gap을 구한다. 5. max 함수를 ..