Interview Prep Day — 5

In continuation to below post

Finished with 5th day of learning. I started with Hibernate Interview questions and did JSP interview questions. I do interview questions so that I can be prepared for any kind of rapid-fire telephonic rounds. Because I don’t when Google can call me. Waiting for my interview with google. But I hope before that I am enough confident about my self.

After doing interview questions I solved the leetcode July challenge question,

Given two numbers, hour and minutes. Return the smaller angle (in degrees) formed between the hour and the minute hand.

The problem with this question was I don’t even know basic maths, so it was not at all possible for me to solve it without cheating, but I didn’t want to cheat so I took my brother’s help and understood the basic maths behind it.

  1. The speed of minutes hand is 6 degrees per minute. How I came to this conclusion as 1 round of circle is completed in 1 hr, 1 hr = 60 mins, and circle is 360 degrees, on dividing 360 / 60 we get the result.

Next question I did was based on strings, which was one of the simplest questions, I make sure that first I try questions using pen and paper and then will solve on the code editor. Even the question was simple I wasn’t able to do it, although I was going in the right track still, I was confused, and finally, have to take help from leetcode solutions

Given a string, find the first non-repeating character in it and return its index. If it doesn’t exist, return -1.

One of the simplest solutions was to

  1. Take HashMap and store the frequency of each character by iterating the string, if value present in hashmap add one to the current frequency, if not then add value in a hashmap with frequency as 1.

I did another question related to String which was

Return the index of the first occurrence of needle in a haystack, or -1 if the needle is not part of haystack.

Example 1:

Input: haystack = "hello", needle = "ll"
Output: 2

Example 2:

Input: haystack = "aaaaa", needle = "bba"
Output: -1

For solving this, used String method indexOf

if(needle.length() > haystack.length() )
return -1;
if(needle == null)
return 0;

int index = haystack.indexOf(needle);
if (index<0) return -1;
else return index;

I tried doing one more question related to a string, and I was again related to maths, and Math sucks. But I soon have to make my self fall in love with maths because math can take me to places. The question was reversing the 32-bit integer, but I haven't done it yet, I am close to the solution and will tell you about this by tomorrow.

Have I told you from tomorrow I will add one more activity to my daily routine which is solving maths problems using programing to improve my maths? Obviously Yes Just Now, I know its a PJ.

After this, I Read MySQL internals book Chapter 4 and you can find highlights over here

Happy Learning!!!