Showing posts with label Coding. Show all posts
Showing posts with label Coding. Show all posts

August 10, 2018

Given strings are Anagram or not?

Write a function to check whether two given strings are anagram of each other or not. An anagram of a string is another string that contains same characters, only the order of characters can be different. For example, “abcd” and “dabc” are anagram of each other.
check-whether-two-strings-are-anagram-of-each-otherWe strongly recommend that you click here and practice it, before moving on to the solution.


Program:
public class Anagram {
public static void main(String[] args) {
String input1 = "d1asu";
String input2 = "adsu";
System.out.println("Given string are input1: " + input1 + ", input2: " + input2);
System.out.println("" + isAnagram(input1, input2));
}
private static String isAnagram(String input1, String input2) {
String result = "Given strings are not anagram";
boolean isAnagram = false;
if (!input1.isEmpty() && !input2.isEmpty() && (input1.length() == input2.length())) {
char[] arr = input1.toCharArray();
StringBuilder sb = new StringBuilder(input2);
for (char a : arr) {
int index = sb.indexOf("" + a);
if (index != -1) {
sb.deleteCharAt(sb.indexOf("" + a));
}
}
isAnagram = sb.toString().isEmpty();
}
if (!isAnagram) {
return result;
}
return "Given strings is anagram";
}
}
Output:
Given string are input1: d1asu, input2: adsu
Given strings are not anagram
Reference:
https://www.devglan.com/java-programs/anagram-test
https://www.geeksforgeeks.org/check-whether-two-strings-are-anagram-of-each-other/


Read more ...

Given String is Pangram or not?


Given a string check if it is Pangram or not. A pangram is a sentence containing every letter in the English Alphabet.
Examples : The quick brown fox jumps over the lazy dog ” is a Pangram [Contains all the characters from ‘a’ to ‘z’]
“The quick brown fox jumps over the dog” is not a Pangram [Doesn’t contains all the characters from ‘a’ to ‘z’, as ‘l’, ‘z’, ‘y’ are missing]
Recommended: Please solve it on “PRACTICE ” first, before moving on to the solution.
We create a mark[] array of Boolean type. We iterate through all the characters of our string and whenever we see a character we mark it. Lowercase and Uppercase are considered the same. So ‘A’ and ‘a’ are marked in index 0 and similarly ‘Z’ and ‘z’ are marked in index 25.
After iterating through all the characters we check whether all the characters are marked or not. If not then return false as this is not a pangram else return true.

Program:

public class Panagram {


public static void main(String[] args) {
String input = "The quick brown fox jumps over the lazy dog";
System.out.println("Panagram test string : "+input);

System.out.println(""+ checkPanagram(input));
}

/**
*Returns true if the string     is pangram else false
* @param input
* @return
*/
private static String checkPanagram(String input) {
String result = "Given string is not panagram";
  // Create a hash table to mark the
        // characters present in the string
        // By default all the elements of
        // mark would be false.
boolean[] mark = new boolean[26];

if(input == null) {
return "Given input is invalid";
}
// For indexing in mark[]
int index = 0;
// Traverse all characters
for(int i=0;i // If uppercase character, subtract 'A'
            // to find index.
if( 'A' <= input.charAt(i) && input.charAt(i)  <= 'Z') {
index = input.charAt(i) - 'A';
System.out.println("current value: "+input.charAt(i)+", index :"+index);
}
// If lowercase character, subtract 'a'
            // to find index.
if( 'a' <= input.charAt(i) && input.charAt(i)  <= 'z') {
index = input.charAt(i) - 'a';
System.out.println("current value: "+input.charAt(i)+", index :"+index);
}
// Mark current character
mark[index] = true;

}
System.out.println("mark: "+mark+", length: "+mark.length);
// Return false if any character is unmarked
for(int j =0;j if(mark[j] == false) {
return result;
}
}
// If all characters were present
return "The Given String is panagram.";
}

}



Output:
Panagram test string : The quick brown fox jumps over the lazy dog
current value: T, index :19
current value: h, index :7
current value: e, index :4
current value: q, index :16
current value: u, index :20
current value: i, index :8
current value: c, index :2
current value: k, index :10
current value: b, index :1
current value: r, index :17
current value: o, index :14
current value: w, index :22
current value: n, index :13
current value: f, index :5
current value: o, index :14
current value: x, index :23
current value: j, index :9
current value: u, index :20
current value: m, index :12
current value: p, index :15
current value: s, index :18
current value: o, index :14
current value: v, index :21
current value: e, index :4
current value: r, index :17
current value: t, index :19
current value: h, index :7
current value: e, index :4
current value: l, index :11
current value: a, index :0
current value: z, index :25
current value: y, index :24
current value: d, index :3
current value: o, index :14
current value: g, index :6
mark: [Z@70dea4e, length: 26
The Given String is panagram.


References:
https://www.geeksforgeeks.org/pangram-checking/

Read more ...

July 24, 2017

how to crack coding the product based company interview?

In product based companies are looking for coding, algorithms, design in depth knowledge.

So we need to concentrate below Cracking The Coding in the first step, for the Gayle giving good tips with examples. I have provided all the web links for the getting good knowledge coding and algorithms. Up coming post will add good design prospective links.

Gayle L McDowell  teachings in youtube:
https://www.youtube.com/watch?v=rEJzOhC5ZtQ
https://www.youtube.com/watch?v=lbLZiHvPIKE

Gayle L McDowell teaching ppt location:
http://www.slideshare.net/zukun/gayle-mcdowell-cracking-the-coding-interview

how to prepare a resume with effective way below 10 years of experience:
https://www.careercup.com/resume

Example programs:

Java programs in eclipse workspace:
https://www.careercup.com/careercup_book_solutions

.NET:
https://github.com/ramanujadasu/cracking-the-coding-interview

Scala:
https://github.com/ramanujadasu/cracking-coding-interview

Javascript:
https://github.com/ramanujadasu/cracking-code-interview-javascript

Additional tutorials:
https://www.siliconvalley-codecamp.com/

More interview questions with solutions for product based companies:
https://www.careercup.com/page


Read more ...

My Favorite Site's List

#update below script more than 500 posts