Skip to main content

Posts

Showing posts from September, 2022

Drawing Book HackerRank Solution in Java and Python with Explanation

Java and Python Solution for Drawing Book HackerRank Problem Problem Description : A teacher asks the class to open their books to a page number. A student can either start turning pages from the front of the book or from the back of the book. They always turn pages one at a time. When they open the book, page 1 is always on the right side: When they flip page 1, they see pages 2 and 3. Each page except the last page will always be printed on both sides. The last page may only be printed on the front, given the length of the book. If the book is n pages long, and a student wants to turn to page p, what is the minimum number of pages to turn? They can start at the beginning or the end of the book. Given n and p, find and print the minimum number of pages that must be turned in order to arrive at page p. Example 1 : n = 5 p = 3 ans  = 1 If the student wants to get to page 3, they open the book to page 1, flip 1 page and they are on the correct page. If they open the book to t

How to install Maven on Windows and Set Path to Run properly - blogoncode

Download and Install Apache Maven in Windows System | Set Environment Path of Maven into System Maven is great project management tool that is used for build, Projects. Maven is based on POM (Project Object Model). For use maven, we have to simply download zip file from Maven website and extract it in our system. 1.  Download Maven Zip : Download Maven Zip   Now extract it anywhere you want to. 2. Add into Environment Variable Search for View Advanced System Setting on your Window system Click on Environment Variable Click on New button in System variables Set Variable name as MAVEN_HOME and Variable value as your Maven file location . 3. Add MAVEN_HOME to Path Search for Path in System Variables, Click on Edit button and add %MAVEN_HOME%\bin . 4. Check for Maven installed successfully Open new Command prompt (cmd) and type mvn -version Here you can see Maven information. If above process does not work, Restart your system after setting Environment variable.    We can also set Maven pa

Caesar Cipher Example in Java with Explanation | blogoncode

Caesar Cipher Program in Java for Encryption | HackerRank Solution Caesar cipher is one of the simplest encryption technique. It is also known as Shift cipher, Caesar shift. By using Caesar cipher technique we can replace each letter in the plaintext with different one with fixed number of places.  Example 1 : Plaintext = abcd n = 2 Caesar cipher = cdef Example 2 : Plaintext = xyz n = 3 Caesar cipher = abc Problem Description : Julius Caesar protected his confidential information by encrypting it using a cipher. Caesar's cipher shifts each letter by a number of letters. If the shift takes you past the end of the alphabet, just rotate back to the front of the alphabet. In the case of a rotation by 3, w, x, y and z would map to z, a, b and c. Example : string = Hello, how are you? n = 1 Caesar cipher = Jgnnq, jqy ctg aqw? See full problem description on HackerRank: Caesar Cipher Problem Description   Lets jump on code...   import java.util.Scanner; public class CaesarCipher {