Hackerrank “30 Days of Code” Çözümleri – Day 12: Inheritance

Hackerrank’in 30 Days of Code içerisinde bulunan “Day 12: Inheritance” sorusunun açıklaması ve çözümü. Bu soruda inheritance kavramına göz atıyoruz.

► Hackerrank 30 Days of Code Çözümleri – Day 12: Inheritance: https://www.hackerrank.com/challenges/30-inheritance/problem

► Problem açıklaması:

Objective

Today, we’re delving into Inheritance. Check out the attached tutorial for learning materials and an instructional video.

Task

You are given two classes, Person and Student, where Person is the base class and Student is the derived class. Completed code for Person and a declaration for Student are provided for you in the editor. Observe that Student inherits all the properties of Person.

Complete the Student class by writing the following:

A Student class constructor, which has parameters:

A string, firstName.

A string, lastName.

An integer, idNumber.

An integer array (or vector) of test scores, scores.

A char calculate() method that calculates a Student object’s average and returns the grade character representative of their calculated average:

Input Format

The locked stub code in the editor reads the input and calls the Student class constructor with the necessary arguments. It also calls the calculate method which takes no arguments.

The first line contains firstName, lastName, and idNumber, separated by a space. The second line contains the number of test scores. The third line of space-separated integers describes scores.

Output Format

Output is handled by the locked stub code. Your output will be correct if your Student class constructor and calculate() method are properly implemented.

Sample Input

Heraldo Memelli 8135627

2

100 80

Sample Output

Name: Memelli, Heraldo

ID: 8135627

Grade: O

Hackerrank “30 Days of Code” Çözümleri – Day 11: 2D Arrays

Hackerrank‘in 30 Days of Code içerisinde bulunan “Day 11: 2D Arrays” sorusunun açıklaması ve çözümü. Bu soruda verilen bir list of list şeklindeki yapıda, kum saati şeklindeki elemanlarının toplamının maksimum değerini bulmanız isteniyor.

► Hackerrank 30 Days of Code Çözümleri – Day 11: 2D Arrays: https://www.hackerrank.com/challenges/30-2d-arrays/problem

► Problem açıklaması:

Objective

Today, we are building on our knowledge of arrays by adding another dimension. Check out the Tutorial tab for learning materials and an instructional video.

Context

Given a 6×6 2D Array, A:

1 1 1 0 0 0

0 1 0 0 0 0

1 1 1 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0

We define an hourglass in to be a subset of values with indices falling in this pattern in A’s graphical representation:

a b c

d

e f g

There are 16 hourglasses in A, and an hourglass sum is the sum of an hourglass’ values.

Task

Calculate the hourglass sum for every hourglass in A, then print the maximum hourglass sum.

Hackerrank “30 Days of Code” Çözümleri – Day 10: Binary Numbers

Hackerrank’in 30 Days of Code içerisinde bulunan “Day 10: Binary Numbers” sorusunun açıklaması ve çözümü. Bu soruda verilen sayının binary gösteriminin içerdiği yan yana 1’lerin maksimum sayısını bulmanız isteniyor.

► Hackerrank 30 Days of Code Çözümleri – Day 10: Binary Numbers: https://www.hackerrank.com/challenges/30-binary-numbers/problem

► Problem açıklaması:

Objective

Today, we’re working with binary numbers. Check out the Tutorial tab for learning materials and an instructional video!

Task

Given a base-10 integer, n, convert it to binary (base-2). Then find and print the base-10 integer denoting the maximum number of consecutive ‘1s in n’s binary representation. When working with different bases, it is common to show the base as a subscript.

Example

n = 125

The binary representation of 125 is 1111101. In base 10, there are 5 and 1 consecutive ones in two groups. Print the maximum, 5.

Input Format

A single integer, n.

Output Format

Print a single base-10 integer that denotes the maximum number of consecutive 1’s in the binary representation of n.

Sample Input 1

5

Sample Output 1

1

Sample Input 2

13

Sample Output 2

2

Hackerrank “30 Days of Code” Çözümleri – Day 9: Recursion 3

Hackerrank’in 30 Days of Code içerisinde bulunan “Day 9: Recursion 3” sorusunun açıklaması ve çözümü. Bu soruda rekürsif fonksiyonlara giriş yapıyoruz. Derler ki; “Rekürsif fonksiyonları anlamak için önce rekürsif fonksiyonları anlamanız gerekir“.

► Hackerrank 30 Days of Code Çözümleri – Day 9: Recursion 3: https://www.hackerrank.com/challenges/30-recursion/problem

► Problem açıklaması:

Objective

Today, we are learning about an algorithmic concept called recursion. Check out the Tutorial tab for learning materials and an instructional video.

Recursive Method for Calculating Factorial Function Description Complete the factorial function in the editor below. Be sure to use recursion.

factorial has the following paramter:

int n: an integer

Returns

int: the factorial of n

Note: If you fail to use recursion or fail to name your recursive function factorial or Factorial, you will get a score of 0.

Input Format

A single integer, n (the argument to pass to factorial).

Constraints

– 2 lessEqual n lessEqual 12

– Your submission must contain a recursive function named factorial.

Sample Input

3

Sample Output

6

Explanation

Consider the following steps. After the recursive calls from step 1 to 3, results are accumulated from step 3 to 1.

factorial(3) = 3 x factorial(2) = 3 x 2 = 6

factorial(2) = 2 x factorial(1) = 2 x 1 = 2

factorial(1) = 1

Hackerrank “30 Days of Code” Çözümleri – Day 8: Dictionaries and Maps

Hackerrank’in 30 Days of Code içerisinde bulunan “Day 8: Dictionaries and Maps” sorusunun açıklaması ve çözümü. Bu soruda dictionary ve hash table mantığına göz atıyoruz.

► Hackerrank 30 Days of Code Çözümleri – Day 8: Dictionaries and Maps: https://www.hackerrank.com/challenges/30-dictionaries-and-maps/problem

► Problem açıklaması:

Objective

Today, we’re learning about Key-Value pair mappings using a Map or Dictionary data structure. Check out the Tutorial tab for learning materials and an instructional video!

Task

Given n names and phone numbers, assemble a phone book that maps friends’ names to their respective phone numbers. You will then be given an unknown number of names to query your phone book for. For each name queried, print the associated entry from your phone book on a new line in the form name=phoneNumber; if an entry for name is not found, print Not found instead.

Note: Your phone book should be a Dictionary/Map/HashMap data structure.

Input Format

The first line contains an integer, n, denoting the number of entries in the phone book. Each of the n subsequent lines describes an entry in the form of 2 space-separated values on a single line. The first value is a friend’s name, and the second value is an 8-digit phone number.

After the n lines of phone book entries, there are an unknown number of lines of queries. Each line (query) contains a name to look up, and you must continue reading lines until there is no more input.

Note: Names consist of lowercase English alphabetic letters and are first names only.

Output Format

On a new line for each query, print Not found if the name has no corresponding entry in the phone book; otherwise, print the full name and phoneNumber in the format name=phoneNumber.

Sample Input

3

sam 99912222

tom 11122222

harry 12299933

sam

edward

harry

Sample Output

sam=99912222

Not found

harry=12299933

Hackerrank “30 Days of Code” Çözümleri – Day 7: Arrays

Hackerrank’in 30 Days of Code içerisinde bulunan “Day 7: Arrays” sorusunun açıklaması ve çözümü. Bu soruda size verilen bir liste içerisinde, uzunluğundan ilk index’ine kadar elemanları yazdırmanız isteniyor.

► Hackerrank 30 Days of Code Çözümleri – Day 7: Arrays: https://www.hackerrank.com/challenges/30-arrays/problem

► Problem açıklaması:

Objective

Today, we will learn about the Array data structure. Check out the Tutorial tab for learning materials and an instructional video.

Task

Given an array, A, of N integers, print A’s elements in reverse order as a single line of space-separated numbers.

Example

A=[1, 2, 3, 4]

Print 4 3 2 1. Each integer is separated by one space.

Input Format

The first line contains an integer, N (the size of our array). The second line contains N space-separated integers that describe array A’s elements.

Output Format

Print the elements of array A in reverse order as a single line of space-separated numbers.

Sample Input

4

1 4 3 2

Sample Output

2 3 4 1