Postingan

Menampilkan postingan dengan label String

Top 20 String Algorithm Questions from Coding Interviews

Gambar
In this article, we are going to see top 20 String based coding interview question and their solution to help programmers better prepare for interviews. The string is one of the most important data structure and available in almost every programming language like Java, C, C++, Python, Perl, and Ruby. Though there implement differ the essence remains same like String is NULL terminated character array in C butString is an object in Java, again backed by character array. The string is also available on weekly typed languages like Python and Perl.  This is why you will always find some String based coding question on programming interview. Even in your college days, you would have solved lots of coding problems based upon String like reversing String in place, checking if String is a palindrome, checking if two strings are an anagram of each other, calculating permutations of String etc. The coding questions from programming interviews are also not very different from that, but yes it...

2 Ways to Check if a String is Rotation of Other in Java - Algorithms

Gambar
Write a program to check if one String is a rotation of another String is a common coding problem you will find on programming job interviews.  A String is said to be a rotation of another String, if it has the same length, contains the same characters, and they were rotated around one of the characters. For example,  String"bcda" is a rotation of "abcd" but "bdca" is not a rotation of String "abcd". One of the simplest solutions to this interesting problem is first to check if two String has the same length, if not then one String cannot be the rotation of another. If they are of the same length then just create another String by concatenating first String with itself, now check if second String is a substring of this concatenated String or not, if yes, the second String is a rotation of first. You might be wondering, how does this solution work? Well, you can rotate the String around some character and if you join the String with itself then it...