본문 바로가기

알고리즘/Hackerrank

[Hackerrank] Let's Review Objective Today we will expand our knowledge of strings, combining it with what we have already learned about loops. Check out the Tutorial tab for learning materials and an instructional video. Task Given a string, S , of length N that is indexed from 0 to N - 1, print its even-indexed and odd-indexed characters as 2 space-separated strings on a single line (see the Sample below for more detail.. 더보기
[Hackerrank] Loops Objective In this challenge, we will use loops to do some math. Check out the Tutorial tab to learn more. Task Given an integer, , print its first multiples. Each multiple (where ) should be printed on a new line in the form: n x i = result. Example The printout should look like this: 3 x 1 = 3 3 x 2 = 6 3 x 3 = 9 3 x 4 = 12 3 x 5 = 15 3 x 6 = 18 3 x 7 = 21 3 x 8 = 24 3 x 9 = 27 3 x 10 = 30 Inpu.. 더보기
[Hackerrank] Class vs. Instance Objective In this challenge, we're going to learn about the difference between a class and an instance; because this is an Object Oriented concept, it's only enabled in certain languages. Check out the Tutorial tab for learning materials and an instructional video! Task Write a Person class with an instance variable, age, and a contructor that takes an integer, initialAge, as a parameter. The co.. 더보기
[Hackerrank] Intro to Conditional Statements Objective In the challenge, we learn about conditional statements. Check out the Turorial tab for learning materials and an instructional video. Task Given an integer, n, perform the following confitional actions: if n is odd, print Weird if n is even and in the inclusive range of 2 to 5, print Not Weird if n is even and in the inclusive range of 6 to 20, print Weird if n is even and greater tha.. 더보기
[Hackerrank] Operators Objective In this challenge, you will work with arithmetic operators. Check out the Turtorial tab for learning materials and an instructional video. Task Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the meal's total cost. Round the res.. 더보기
[Hackerrank] Data Types Objective Today, we're discussing data types. check out the Tutorial tab for learning materials and an instructional video! Task Complete the code in the editor below. The variables i, d, and s are already declared and initalized for you. You must: 1. Declare 3 variables: one of type int, one of type double, and one of type String. 2. Read 3 lines of input from stdin (according to the sequence g.. 더보기
[Hackerrank] Picking Numbers Given an array of integers, find the longest subarray where the absolute difference between any two elements is less than or equal to 1. Example a = [1,1,2,2,4,4,5,5,5] There are two subarrays meeting the criterion: [1,1,2,2] and [4,4,5,5,5]. The maximum length subarray has 5 elements. Function Description Complete the pickingNumbers function in the editor below. pickingNumbers has the following.. 더보기
[Hackerrank] Forming a Magic Square We define a magic square to be an n x n matrix of distinct positive integers from 1 to n2 where the sum of any row, column, or diagonal of length n is always equal to the same number: the magic constant. You will be gicen a 3 x 3 matrix s of integers in the inclusive range [1,9]. We can convert any digit a to any other digit b in the range [1,9] at cost of |a-b|. Given s, convert it into a magic.. 더보기