Monday, November 23, 2015

Minimum No. of Jumps

Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Your goal is to reach the last index in the minimum number of jumps.
Example :
Given array A = [2,3,1,1,4]
The minimum number of jumps to reach the last index is 2. (Jump 1 step from index 0 to 1, then 3 steps to the last index.)
If it is not possible to reach the end index, return -1.

 Follow this link to read a O(n^2) solution GeeksforGeeks: Minimum number of jumps

Read my O(n) solution below

Sunday, October 11, 2015

Maximum Product Subarray

One of the standard dp problems, the approach given below is similar to kadane algorithm for maximum subarray sum problem. The code given below fails when negative output is the max possible. For example the input

Input : -4


Comments are welcome.

Monday, August 31, 2015

Preparing for the Coding Interview

Here are a few things that I did while preparing for my placements and a few things that I think I should have done.

This post is written with the plan that you have max of 6 months left before the D-Day, for people in the their 2nd or 3rd years there is a variety of things that would further enhance their chances of being placed.

<-------------------------- 6 Months -------------------------------->
www.geeksforgeeks.org    This is a very big repository of coding interview questions and preparations material. Usually one would require about 6 months to go through the whole material.

<--------------------------- 4 - 5 Months --------------------->

After having read the standard algorithms and Data Structures, its time to gain some coding experience

www.interviewbit.com This site is very good for coders with not much experience, you will have revision of concepts and get practice at the same time. It provides a gaming level sort of UI to make it interesting, which a growing community.

www.leetcode.com This is another site is popular among coders for interview preparation, but many questions between interviewbit and this overlaps so do one of them. InterviewBit has more structure and organization for preparation.

<------------------------------1-2 Months ---------------------------->

Hopefully above level of preparation would be sufficient for clearing hte coding rounds and you are now shortlisted your dream companies. So brush up the topics on your resume and prepare for the specific domains like Networks, OS .

Some important topics to prepare for :
1. Linked List
2. Stacks and Queues
3. Dynamic Programming ( geeksforgeeks has an extensive collection)
4. Greedy
5. Backtracking 
6. Graph Theory ( dfs and bfs will do for most except google,fb ) 


Comments and suggestions are welcome .