Any question related to computer science is a fair game in an interview, because believe it or not – you do need knowledge of most of these things for the job when working on a project. Although it’s not feasible to study everything, you can be strategic about the preparation and prioritize one thing over the other depending upon how much time you have for your next interview. … More What you should study for a successful interview loop
The idea behind solving dynamic programming problems is simple – remember what you have already solved and use the already computed solution in case you are solving the same problem again. In other words, solve one problem only once and remember the solution to it so that you can quickly provide the solution without the need to solve the problem again. … More Dynamic Programming
For any problem, usually, there are multiple ways to tackle it. Solving a coding problem in an interview is no different. There are almost always multiple solutions to the given problem. Each solution has some cost i.e. time and space complexity associated with it. Your job is to identify various solutions, analyze their time & space complexities, discuss this with the interviewer, and implement the most suitable solution depending on the inputs and constraints. … More Analysis of Algorithms | Big-O Analysis
When you get stuck in an interview, you have the opportunity to actually get maximum points from the interviewer as long as you keep the positive attitude and logical approach. Ideally, the interviewer would like to see the candidate struggle and then find the solution. This way, they are able to see how you tackle the problems in the real world. … More Stuck on a problem in coding interview? Here is how to poke the problem towards solution
The purpose of this post is to remind you of a variety of common things that you would need when writing the code in the coding interview. What you must do is to check the syntax of that thing in the language of your choice. I have listed most of the things that I have ever had to use across all the interviews I have appeared for. Some things are necessary for pretty much every interview while others are rare. I recommend studying everything even if it is a rarely necessary thing because I want to enable you to crack every coding interview. … More What things you should know how to do in your programming language
It is definitely not easy, but you can greatly improve the odds if you nail the following approach. I am going to explain the key elements that you need to get right to crack the interview. How many times you solve the question, code it completely, but still don’t clear the interview? This post is an attempt to stop this happening with you. … More How you can crack every coding interview
As we have already solved “Two Sum” problem already, let’s reuse our existing knowledge to solve this problem. We know the target and we want to search 3 numbers. We know how to search 2 numbers, so if we fix one number at a time and look for the other two numbers using our previous solution that would solve this problem as well.
What is the maximum possible sum of any two numbers from the array? It is sum of highest 2 numbers. Similarly, minimum sum is sum of lowest 2 numbers. Target is going to be somewhere in between these two numbers. What if we start in the middle? … More Leetcode 167. Two Sum II – Input array is sorted
Now that we know 3rd step can be reached directly from 1st and 2nd, what will be the number of ways in which we can reach the step 3? It would be all the ways in which we can reach the step 1 (because we can always take 2 steps from here to reach the step 3) + the number of ways in which we can reach the step 2 (because we can always take 1 more step to reach the step 3). … More Leetcode 70. Climbing Stairs
once we fix one number, say K, then we know what the other number must be and i.e. target-K. For any other number, they won’t add up to the target. Now if we know that search is a vital operation, employ the best data structure for the search i.e. hash set. … More Leetcode 1. Two Sum
Certainly, a “Flip” is a must when the current status of a bulb at index i and it’s the target status are not the same.
Initially all bulbs are OFF i.e. 0 and when a bulb at index i is flipped, every bulb after (in the right -> direction) that bulb gets flipped. So it only makes sense to start getting the status of the bulbs correct int the left to right order. … More Leetcode #1529: Bulb Switcher IV
The problem is a lot about observation. Observing and analyzing the ant behavior will reveal that the problem is way too tricky to understand but way too easy to implement. The idea is to think of the bigger picture and focus only on the paths of the ants. At any collision, think of it as ants transferring their responsibility … … More Leetcode #1503: Last Moment Before All Ants Fall Out of a Plank
Secondly, we need to add a number in front in case of a conflict. So each folder name should have a number associated with it. The most intuitive data structure for this is a hash map. The corner case we need to handle is that what if we append a number as a suffix and generate … … More Leetcode #1487: Making File Names Unique
When drying lake #L, it is only useful to dry it if it is FULL already. Otherwise, it’s just a waste to dry an empty lake. (Explained this in the code with a small example as well). In short, drying a lake #L only makes sense if it is already FULL and it is going to rain on that lake in future.
Which lake to dry on a day when there is no rain, can not be determined without knowing the rain sequence that is coming next. … More Leetcode #1488: Avoid Flood in The City
So the only task for us is to find what would be the height and width of each piece after all cuts and then find the piece with maximum height and width. Each cut in the cake, divides the cake into pieces with certain height and certain width. We want to maximize the area … … More Leetcode #1465: Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
For example, say at t=0, t=1, and t=2, the number of frogs that are croaking is 1, 2, and 1 respectively. Finding how many frogs are croaking at any time is also not difficult. We know that each “croaking” starts with a ‘c’ and ends with a ‘k’. … More Leetcode #1419: Minimum Number of Frogs Croaking