Photo by John Lockwood on Unsplash

I have published an ebook. A compilation of 100 Java(Interview)Programming problems which have been solved . I have given clear explanation and the code in the book. Believe me when I say, this will kick start you to achieve the job at your dream company.

Click on this link to get you to the landing page. It is completely free when you use kindle amazon. Take a look at it.

It is Completely free if you have Kindle Unlimited plan. It is worth the read if you want to learn java on your mobile and if you can’t take a paperback to each and every place you travel to. Let’s get to the Problem now

3)Find the intersection of two given string. Return the string which has character which appears in both string (same sequence order as string1).

Input Format: String1: "Hello" String2: "world"

Output Format: "lo"

Input Format: String 1: "hi" String2: "bye"

Output Format: null

Code:

Explanation:

The problem is to compare the two input string and to return the characters that are repeated in both the strings.

To find the characters that are repeated we use looping conditions and check whether the character in one input string matches with all the other characters of the other input string. By this method we could find the character that is repeated in both the strings.

Algorithm:

  • Read the input strings from the user that is passed to function and then convert it into a character array st1 and st2.
  • Declare a character array st[ ] that is of the same size of the input string and initialize it to null.
  • Using two for loops we compare the characters of the input string using the == condition.
  • If any of the character of the input strings are same it is appended to the array st[ ].
  • The value of the iterator is incremented after checking each and every character of the input string.

Conclusion

No Single Solution exists to a problem.Work on the Code. Share your Thoughts with me. These problems are from HackerRank.

You can follow House of Codes to receive updates when we post new coding challenges. Also you could send us your solutions or your ideas for any coding challenge. We would be thrilled to read them. ;)

Code -> Understand-> Repeat is my motto. I am a Data Engineer who writes about everything related to Data Science and Interview Preparation for SDE.

Code -> Understand-> Repeat is my motto. I am a Data Engineer who writes about everything related to Data Science and Interview Preparation for SDE.