Here are some other ways to access array objects in Ruby. To access the elements from the end of the list, we can use negative indices. For the array, arr = [9, 5, 1, 2, 3, 4, 0, -1] > arr[-1] => -1 The first element of…
Array collections offer various ways to access their elements. The positions are 0 indexed. Objects of the array can be accessed using the [] method which may take various arguments, as explained below. arr = [9, 5, 1…
One of the most commonly used data structures in Ruby is a Ruby Array, and below we see various methods of initializing a ruby array. Your task is to initialize three different variables as explained below. Initialize…
This challenge has a beautiful one-liner answer. "A hacker practices on HackerRank until getting to a rating of O(1) read as (Oh-one)" Call the method coder.practice until coder.oh_one? becomes true. Use the until…
This is a wonderful exercise which explains the concept of infinite loops. "A hacker practices on HackerRank until getting to a rating of O(1) read as (Oh-one)" An infinite loop in Ruby is of the form Use an infinite…
You've updated the score of every HackerRank user who participated in a contest. Sometimes, HackerRank admins also participate in a given contest but care is taken to ensure that their submissions do not get any score…
Ruby offers control structures that let you iterate through its collections. One such control structure is each. As you already know, HackerRank conducts many contests, and for every user who participates in a contest…
A method may take zero or more parameters as input. To demonstrate this, we look at the asserts we use on HackerRank. Sometimes, we have to check whether a given number a is within the range b and c (where b c, and both…
Each object in Ruby may have methods associated with it. To demonstrate this, we want you to print whether a number is even or odd. A number has an even? method associated with it, which returns true or false based on…
Everything is an object in Ruby. For instance, if you type print self in the code-editor, Ruby treats self as the object in which it is currently referred to. Give it a try! Solution in ruby
You are given an array and you need to find number of tripets of indices such that the elements at those indices are in geometric progression for a given common ratio and . For example, . If , we have and at indices and…
Starting with a 1-indexed array of zeros and a list of operations, for each operation add a value to each of the array element between two given indices, inclusive. Once all operations have been performed, return the…
Starting with a 1-indexed array of zeros and a list of operations, for each operation add a value to each of the array element between two given indices, inclusive. Once all operations have been performed, return the…
Objective This challenge will help you learn the concept of recursion. A function that calls itself is known as a recursive function. The C programming language supports recursion. But while using recursion, one needs…
Objective This challenge will let you learn about bitwise operators in C. Inside the CPU, mathematical operations like addition, subtraction, multiplication and division are done in bit-level. To perform bit-level…
Objective In this challenge, you will learn the usage of the for loop, which is a programming language statement which allows code to be repeatedly executed. The syntax for this is expression_1 is used for intializing…
Objective if and else are two of the most frequently used conditionals in C/C++, and they enable you to execute zero or one conditional statement among many such dependent conditional statements. We use them in the…
Objective In this challenge, you will learn to implement the basic functionalities of pointers in C. A pointer in C is a way to share a memory address among different contexts (primarily functions). They are primarily…
Objective In this challenge, you will learn simple usage of functions in C. Functions are a bunch of statements glued together. A function is provided with zero or more arguments, and it executes the statements on it…