본문 바로가기

Algorithm101

Count the divisors of a number Description: Count the number of divisors of a positive integer n. Random tests go up to n = 500000. Examples (input --> output) 4 --> 3 (1, 2, 4) 5 --> 2 (1, 5) 12 --> 6 (1, 2, 3, 4, 6, 12) 30 --> 8 (1, 2, 3, 5, 6, 10, 15, 30) Solution: 1. Repeat 'n' to generate numbers one after the other. 2. Check whether the generated numbers are divisible by 'n'. 3. Count the number of divisible numbers. fu.. 2022. 3. 12.
Abbreviate a Two Word Name Description: Write a function to convert a name into initials. This kata strictly takes two words with one space in between them. The output should be two capital letters with a dot separating them. It should look like this: Sam Harris => S.H patrick feeney => P.F solution: 1. Change the name to all uppercase letters. 2. Separate strings based on space and put them in an array. 3. Put the first .. 2022. 3. 6.
Equal Sides Of An Array Description: You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, return -1. For example: Let's say you are given the array {1,2,3,4,3,2,1}: Your function will return the index 3, because at the 3rd p.. 2022. 3. 5.
Is this a triangle? Description: Implement a function that accepts 3 integer values a, b, c. The function should return true if a triangle can be built with the sides of given length and false in any other case. (In this case, all triangles must have surface greater than 0 to be accepted). Solution: 1. Sort a, b, c in ascending order. 2. Compare the last number (largest number) with the sum of the remaining two num.. 2022. 3. 4.
Sum of Numbers Description: Given two integers a and b, which can be positive or negative, find the sum of all the integers between and including them and return it. If the two numbers are equal return a or b. Note: a and b are not ordered! Examples (a, b) --> output (explanation) (1, 0) --> 1 (1 + 0 = 1) (1, 2) --> 3 (1 + 2 = 3) (0, 1) --> 1 (0 + 1 = 1) (1, 1) --> 1 (1 since both are same) (-1, 0) --> -1 (-1 .. 2022. 3. 3.
Counting Duplicates Description: Count the number of Duplicates Write a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits. Example "abcde" -> 0 # no characters repeats more than once "aabbcde" -> 2 # 'a' and.. 2022. 3. 1.