Tip 1: Have three unique, full-stack projects tailored to the role you are applying for.
Tip 2: Avoid including inaccurate information on your resume.



Given a string and a number k, find the longest substring that has at most k distinct characters.
Step 1: I started by thinking about how to approach this problem using two pointers. Initially, I set both the left and right pointers at the start of the string, and thought about expanding the window by moving the right pointer to the right.
Step 2: I realized that as the window expanded, I needed to track how many distinct characters were in the window. So, I used a hashmap (or dictionary) to count the frequency of each character within the window.
Step 3: As I moved the right pointer, I kept updating the hashmap with the character counts. If the number of distinct characters (i.e., the size of the hashmap) ever exceeded k, I knew I needed to shrink the window. So, I moved the left pointer to the right until the window had at most k distinct characters again.
Step 4: While doing this, I kept track of the maximum length of the window that satisfied the condition (at most k distinct characters).
Step 5: This approach only required one pass through the string, making it much more efficient (O(n)) compared to using nested loops or sorting



Given a collection of intervals, merge all overlapping intervals
Step 1: I started by thinking about how to handle the intervals. The first thing that came to mind was sorting the intervals based on their start times. This seemed like a natural approach because if intervals are sorted, any overlapping intervals will be next to each other.
Step 2: Once the intervals were sorted, I knew I had to check each interval against the last merged interval. If the current interval started before the last merged interval ended, I would merge them. This would mean updating the end of the merged interval to the maximum of the two ends.
Step 3: If the current interval didn’t overlap with the last merged interval, I would just add the current interval to the list of merged intervals.
Step 4: After completing the entire list of intervals, I would have the final list with all overlaps merged.
Step 5: I realized this could be done in O(n log n) time complexity because sorting the intervals takes O(n log n), and then merging the intervals in a single pass is O(n). This seemed to be the most efficient approach.



Write a code to find highest and lowest value of the array in single traversal
Step 1: I started by iterating through the array and comparing each element with the current highest and lowest values. Initially, I set the first element as both the highest and lowest. This seemed like the simplest approach.
Step 2: The interviewer asked me to optimize the solution since this could be done in a more efficient way, and it didn’t require sorting or multiple passes through the array.
Step 3: I then realized that I could achieve this in a single traversal by updating the highest and lowest values as I went through the array, comparing each element with the current maximum and minimum values. This way, I reduced the complexity to O(n), which was much better.



Write a program to traverse a tree and visit all its nodes level by level, starting from the top and return the traversal in a list or array.
Step 1: At first, I considered using recursion to traverse the tree, but I quickly realized that it wasn’t the best approach for visiting nodes level by level.
Step 2: So, I switched to using a queue. I added the root node to the queue and started processing its children one at a time.
Step 3: As I moved through each level, I kept adding the child nodes of the current level into the queue. This helped me traverse the tree level by level, and the interviewer seemed happy with how I approached the problem.



Write a program to detect if there was a cycle in an undirected graph. The problem could involve using Depth First Search (DFS) or other traversal techniques to check for cycles.
Step 1: I started by iterating through the array and comparing each element with the current highest and lowest values. Initially, I set the first element as both the highest and lowest. This seemed like the simplest approach.
Step 2: The interviewer asked me to optimize the solution since this could be done in a more efficient way, and it didn’t require sorting or multiple passes through the array.
Step 3: I then realized that I could achieve this in a single traversal by updating the highest and lowest values as I went through the array, comparing each element with the current maximum and minimum values. This way, I reduced the complexity to O(n), which was much better.

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
What is recursion?