Skip to main content

Posts

Showing posts from October, 2020

Arrays Left Rotation in Java | HackerRank Solution

Arrays Left and Right Rotation in Java | HackerRank Solution for Array Left Rotation. Example 1 :- Array Left Rotation by any given number in java (Approach 1) import java.util.Arrays; import java.util.Scanner; public class ArraysLeftRotation {     public static void main(String[] args) {                          Scanner sc = new Scanner(System.in);                   System.out.println("Enter size of Array");         int sizeOfArray = sc.nextInt();         System.out.println("Enter values");         int[] array = new int[sizeOfArray];         for (int i = 0; i < sizeOfArray; i++) {             array[i] = sc.nextInt();         }         System.out.println("Enter number of left rotation");         int rotation = sc.nextInt();                         // Loop until given rotation         for (int i = 0; i < rotation; i++) {                          // Store first array element into temp variable             int tempVariable = array[0];                   

2D Array DS HackerRank Solution | Java Solution | Programming Blog

Two Dimensional Array Solution in Java Problem Statement :- Given 6 * 6 Two Dimensional Array. 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  An hourglass in A is a subset of values with indices falling in this pattern in array's graphical representation. a b c d e f g There are 16 hourglass in Array . An hourglass sum is the sum of an hourglass' values. Calculate the hourglass sum for every hourglass in Array . then print the maximum hourglass sum. The array will always be 6 * 6. Example :- Array -9 -9 -9 1 1 1 0 -9 0 4 3 2 -9 -9 -9 1 2 3 0 0 8 6 6 0 0 0 0 -2 0 0 0 0 1 2 4 0 Then 16 hourglass sum are -63, -34, -9, 12, -10, 0, 28, 23, -27, -11, -2, 10, 9, 17, 25, 18 The highest hourglass sum is 28. 0 4 3 1 8 6 6 So lets see solution of this problem in Java. public class TwoDArrayDS {          public static void main(String[] args) {                 Scanner scanner = new Scanner(System.in);                 // Initialize

Repeated String HackerRank Solution | Java Solution | Programming Blog

Repeated String Solution in Java Lilah has a string s of lowercase English letters that she repeated infinitely many times. Given an integer n , find and print the number of letter a in the first n letters of Lilah's infinite string. For example, if the string s = "abcac" and n = 10 , the substring we consider it "abcacabcac" the first 10 character of her infinite string. There are 4 occurrences of a in the substring. So let's see solution of that. import java.util.Scanner; public class RepeatedString {     public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         System.out.println("Enter Number");         int number = sc.nextInt();         System.out.println("Enter String");         String str = sc.next();                 int lengthOfstr = str.length();                 long occurenceOfA = 0;          // Get all occurence of 'a' in given string         for(int i=0; i< lengthOfstr;i++

Counting Valleys HackerRank Solution | Java Solution

Counting Valleys HackerRank Solution in Java An avid hiker keeps meticulous records of their hikes. During the last hike that took exactly steps. , for every step it was noted if it was an Uphil ,U or Downhill, D. Hikes always start and end at sea level, and each step up or down represents a 1unit change in altitude. We define the following terms: A mountain is a sequence of consecutive steps above sea level, starting with a step up from sea level and ending with a step down to sea level.   A valley is a sequence of consecutive steps below sea level, starting with a step down from sea level and ending with a step up to sea level. Given the sequence of up and down steps during a hike, find and print the number of valleys walked through.   In this post, We do discuss two solution of  "Counting Valleys" problem. so lets see first one. Solution 1 public class CountingValleys{     public static void main(String[] args) {         Scanner scanner = new Scanner(System.in);

Top 10 websites for Competitive Programming In 2021 | Programming Blog

Best websites for Competitive programming and Coding In 2021 1. Hacker Rank    HackerRank is best website where you can solve coding questions. In HackerRank coding problems are divided into Three Parts :- Hard Medium Easy And HackerRank support many languages so you can solve problem in your favourite Programming Language.  hackerrank  2. Hacker Earth In HackerEarth, You can practice programming, prepare for interviews, and level up your coding skills with a community of 5M+ developers. Remotely assess, interview, and hire developers across all roles based on skills. Host virtual hackathons and bring together people with diverse skills and solve business challenges hackerearth   3. Code Chef   CodeChef is a competitive programming community of programmers from across the globe.   codechef     4. Code Forces   Codeforces is a website that hosts competitive programming contests. Codeforces 5. Project Euler   Project Euler is a website dedicated to a series of computational problems i