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.
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.
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.
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.
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’in 30 Days of Code içerisinde bulunan “Day 6: Let’s Review” sorusunun açıklaması ve çözümü. Bu soruda size verilen bir string‘in çift ve tek index’teki karakterlerini ayrı ayrı yazdırmanız isteniyor.
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).
Note: 0 is considered to be an even index.
Example
s = adbecf
Print abc def
Input Format
The first line contains an integer, T (the number of test cases).
Each line i of the T subsequent lines contain a string, S.
Output Format
For each String (where ), print ‘s even-indexed characters, followed by a space, followed by ‘s odd-indexed characters.
Hackerrank’in 30 Days of Code içerisinde bulunan “Day 5: Loops” sorusunun açıklaması ve çözümü. Bu soruda loop (döngü) mantığını ve her bir döngüdeki değişkenleri nasıl kullanabileceğimizi öğrendik.
Hackerrank’in 30 Days of Code içerisinde bulunan “Day 4: Class vs. Instance” sorusunun açıklaması ve çözümü. Bu soruda sınıf ve field’lar üzerinde işlemler yapıyoruz.
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 constructor that takes an integer, initialAge, as a parameter. The constructor must assign initialAge to age after confirming the argument passed as initialAge is not negative; if a negative argument is passed as initialAge, the constructor should set age to 0 and print Age is not valid, setting age to 0.. In addition, you must write the following instance methods:
yearPasses() should increase the age instance variable by 1.
amIOld() should perform the following conditional actions:
If age less than 13, print You are young..
If age bigger or equal than 13 and age less than 18, print You are a teenager..
Otherwise, print You are old..
To help you learn by example and complete this challenge, much of the code is provided for you, but you’ll be writing everything in the future. The code that creates each instance of your Person class is in the main method. Don’t worry if you don’t understand it all quite yet!
Note: Do not remove or alter the stub code in the editor.
Input Format
Input is handled for you by the stub code in the editor.
The first line contains an integer, T (the number of test cases), and the T subsequent lines each contain an integer denoting the age of a Person instance.
Constraints
Output Format
Complete the method definitions provided in the editor so they meet the specifications outlined above; the code to test your work is already in the editor. If your methods are implemented correctly, each test case will print or lines (depending on whether or not a valid was passed to the constructor).
Sample Input
4
-1
10
16
18
Sample Output
Age is not valid, setting age to 0.
You are young.
You are young.
You are young.
You are a teenager.
You are a teenager.
You are old.
You are old.
You are old.
The extra line at the end of the output is supposed to be there and is trimmed before being compared against the test case’s expected output. If you’re failing this challenge, check your logic and review your print statements for spelling errors.
Hackerrank’in 30 Days of Code içerisinde bulunan “Day 3: Intro to Conditional Statements” sorusunun açıklaması ve çözümü. Bu soruda karşılaştırma operatörlerine giriş yapıyoruz.
Hackerrank‘in 30 Days of Code içerisinde bulunan “Day 2: Operators” sorusunun açıklaması ve çözümü. Bu soruda size verilen yemek ücreti, bahşiş ve vergi yüzdeleri ile birlikte toplamda ne kadar para ödemeniz gerektiğinizi bulmanız isteniyor.
In this challenge, you will work with arithmetic operators. Check out the Tutorial 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 result to the nearest integer.
Example
mealCost = 100
tipPercent = 15
taxPercent = 8
A tip of 15% * 100 = 15, and the taxes are 8% * 100 = 8. Print the value 123 and return from the function.
Function Description
Complete the solve function in the editor below.
solve has the following parameters:
int meal_cost: the cost of food before tip and tax
int tip_percent: the tip percentage
int tax_percent: the tax percentage
Returns The function returns nothing. Print the calculated value, rounded to the nearest integer.
Note: Be sure to use precise values for your calculations, or you may end up with an incorrectly rounded result.
Input Format
There are 3 lines of numeric input:
The first line has a double, mealCost (the cost of the meal before tax and tip).
The second line has an integer, tipPercent (the percentage of mealCost being added as tip).
The third line has an integer, taxPercent (the percentage of mealCost being added as tax).
Hackerrank’in 30 Days of Code içerisinde bulunan “Day 1: Data Types” sorusunun açıklaması ve çözümü. Bu soruda sizin konsol‘dan aldığınız int, double ve string tipinde değişkenlerini “+” operatörü kullanarak konsola yazdırmanız isteniyor.
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 , , and are already declared and initialized 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 given in the Input Format section below) and initialize your 3 variables.
3. Use the + operator to perform the following operations:
– Print the sum of i plus your int variable on a new line.
– Print the sum of d plus your double variable to a scale of one decimal place on a new line.
– Concatenate s with the string you read as input and print the result on a new line.
Note: If you are using a language that doesn’t support using + for string concatenation (e.g.: C), you can just print one variable immediately following the other on the same line. The string provided in your editor must be printed first, immediately followed by the string you read as input.
Input Format
The first line contains an integer that you must sum with i.
The second line contains a double that you must sum with d.
The third line contains a string that you must concatenate with s.
Output Format
Print the sum of both integers on the first line, the sum of both doubles (scaled to 1 decimal place) on the second line, and then the two concatenated strings on the third line.
Sample Input
12
4.0
is the best place to learn and practice coding!
Sample Output
16
8.0
HackerRank is the best place to learn and practice coding!
Explanation
When we sum the integers 4 and 12, we get the integer 16.
When we sum the floating-point numbers 4.0 and 4.0, we get 8.0.
When we concatenate HackerRank with is the best place to learn and practice coding!, we get HackerRank is the best place to learn and practice coding!.
You will not pass this challenge if you attempt to assign the Sample Case values to your variables instead of following the instructions above and reading input from stdin.