Interview Prep Day — 5

Navneet Ojha
3 min readJul 14, 2020

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.
  2. Now we know 1 minute is 6 degrees and how much would be the speed of hour hand, We know very well that it takes 12 hrs for an hour hand to complete a circle, so diving 360/12*60 will get the result of 0.5 degrees or 1/2 degree
  3. Now we know the speed of the hour and minute hand, for finding out the angle we need to subtract mins * 6 — hour*60 + mins*0.5, if the hour hand is at 12 we will set it zero.
  4. For hour = 12 and mins = 30 , we can calculate 30*6–0*60 +30*05 = 180–15 = 165 degree
  5. There is one more point left which is we have to give the smallest angle as a result, so we will find out the min out of 360 — angle or angle. Whichever will be the minimum is 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.
  2. Iterate again the string and check one by one the frequency from hashmap starting from the index 0, if the frequency is equal to 1 then it is the result index

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!!!

--

--

Navneet Ojha

I am Indian by birth, Punjabi by destiny. Humanity is my religion. Love to eat, travel, read books and my million dreams keep me alive.