Skip to main content

Pangram : Problem on hackerrank

This is a problem mentioned on Hackerrank. Below is my attempt to solve this problem.

Problem Statement
Roy wanted to increase his typing speed for programming contests. So, his friend advised him to type the sentence "The quick brown fox jumps over the lazy dog" repeatedly because it is a pangram. ( pangrams are sentences constructed by using every letter of the alphabet at least once. )
After typing the sentence several times, Roy became bored with it. So he started to look for other pangrams.
Given a sentence s, tell Roy if it is a pangram or not.



import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] str = in.nextLine().toCharArray();
        boolean[] resultArr = new boolean[26];
int smallMax = 'z';
int capMax = 'Z';

for (int i = 0; i < str.length; i++) {
if (str[i] >= 'a' && str[i] <= 'z') {
resultArr['z' - str[i]] = true;
} else if (str[i] >= 'A' && str[i] <= 'Z') {
resultArr['Z' - str[i]] = true;
}
}
boolean flag = true;
for (int j = 0; j < resultArr.length; j++) {
if (resultArr[j] == false) {
flag= false;
break;
}
}
if(flag == true){
System.out.println("pangram");
}else{
System.out.println("not pangram");
}

    }
}

Comments

  1. Nice informative post! Thanks for sharing the code. Here is my blog where I share valuable information like this too. Learn the Touch typing technique and make your typing fast.

    ReplyDelete

Post a Comment

.

Popular posts from this blog

Carnivorous Island from "Life of PI"

Yann Martel described about an floating carnivorous Island for symbolizing that something seemingly good in life can turn out to be harmful, so we should keep going with our journey of life... About the carnivorous Island from movie. In the movie 'Life of PI' after PI struggles to live in the pacific with the Bengal tiger suddenly one morning Pi  found himself at a Island. After spending so many days in the middle of the sea he found himself very lucky to find a Island. After spending some time he thought might be this was the end of his suffering and he can spend rest of his life at that island. He makes h is bed on a tree and sleeps there, in the middle of the night he wakes up and find that there were dead fish in the fresh water where he took swim in the day time. While trying to understand the mystery he plucks a fruit from the same tree and peel it off and finds a human tooth inside that fruit and then he realize that it was an carnivorous Island. The...

Create Table in Liquibase

For creating table using liquibase you can use below code and add it in your liquibase file. <createTable tableName=“employee”>      <column name="id" type="int">      <constraints primaryKey="true" nullable="false"/>   </column>      <column name="first_name" type="varchar(255)"/>   <column name="last_name" type="varchar(255)"/>   <column name="username" type="varchar(255)">      <constraints unique="true" nullable="false"/>   </column> </createTable> The use is pretty simple it's the way it looks : Tag: <createTable></createTable> This is an opening/ending tag for creating a table. These tags will enclose column sub tags which will define columns for the table. Attribute:   tableName : Name of the table which you want to create. (This is a mandatory   ...

liquibase.exception.LockException: Could not acquire change log lock. Currently locked by...

liquibase.exception.LockException: Could not acquire change log lock. Currently locked by... Solution : Open your database and find the table named 'Databasechangeloglock', check the content of the Locked column. If it is set to '1' in that case the above exception will be thrown. Try setting it to '0' and set content of the 'LOCKGRANT' and 'LOCKEDBY' to (null). You might find this interesting. http://apdynamicviews.blogspot.in/2012/08/how-databasechangeloglock-and.html