Tip 1: Don't waste much time on easy questions
Tip 2: If you can't make a solution to the problem. Check out other's solution
Tip 3: Do some good projects
Tip 1: Write only those skills in which you are confident
Tip 2: Have a variety of achievements in your resume
This was an online coding round with 4 coding questions.


If the given matrix is:
[ [1, 2, 5],
[3, 4, 9],
[6, 7, 10]]
We have to find the position of 4. We will return {1,1} since A[1][1] = 4.
This was the standard problem. I directly solved this through binary search with a little bit of modification.



1)The amount of petrol that is available at this particular petrol pump.
2)The distance to reach the next petrol pump.
I first wrote some random test cases and tried to find solutions manually.
Then I observed one hint in the solutions if we can't reach any point, then any point before that point can't be the answer.
Finally, after a lot of trials, I solved this in linear time.



If the input string is "abbc", then all the possible palindromic substrings would be: ["a", "b", "b", c", "bb"] and hence, the output will be 5 since we have 5 substrings in total which form a palindrome.
A string is said to be a 'Palindrome' if it is read the same forwards and backwards.
For example, “abba” is a palindrome, but “abbc” is not.
A 'Substring' is a contiguous sequence of characters within a string.
For example, "a", "b", "c", "ab", "bc", "abc" are substrings of "abc".
I was not able to write the tabular DP solution at that instant, so I wrote recursive solution with memorization.
Interviews were conducted in offline mode.



If more than one such contiguous subarrays exist, consider the subarray having the smallest leftmost index.
For example - if A is [1, 2, 2, 3, 1, 3 ] and k = 2 then the subarrays: [1,2], [2,3], [3,1], [1,3] are the smallest subarrays containing 2 distinct elements. In this case, we will consider the starting and ending index of subarray [1,2] i.e. 0 and 1.
In the first step, I told the brute force approach.
Then I solved this problem using sliding window.



If the given array is [1, 3, 2], then you need to return [3, -1, -1]. Because for 1, 3 is the next greater element, for 3 it does not have any greater number to its right, and similarly for 2.
I just reversed the array and wrote the code for next greater element. Then reversed the resultant array.
All the questions were based on graph.



Input:
4 5
0 1 5
0 2 8
1 2 9
1 3 2
2 3 6

In the given input, the number of vertices is 4, and the number of edges is 5.
In the input, following the number of vertices and edges, three numbers are given. The first number denotes node ‘X’, the second number denotes node ‘Y’ and the third number denotes the distance between node ‘X’ and ‘Y’.
As per the input, there is an edge between node 0 and node 1 and the distance between them is 5.
The vertices 0 and 2 have an edge between them and the distance between them is 8.
The vertices 1 and 2 have an edge between them and the distance between them is 9.
The vertices 1 and 3 have an edge between them and the distance between them is 2.
The vertices 2 and 3 have an edge between them and the distance between them is 6.
1. There are no self-loops(an edge connecting the vertex to itself) in the given graph.
2. There can be parallel edges i.e. two vertices can be directly connected by more than 1 edge.
Found all shortest path using Dijkstra Algorithm with little modification.
Took the union of edges of all the paths.



Input: 'n' = 4,
'accounts' = [
["Rohan", "rohan123@gmail.com", "1279ro@gmail.com"],
["Rohit", "rohit101@yahoo.com", "hitman30487@gmail.com"],
["Rohan", "1279ro@gmail.com", "niemann01@gmail.com"],
["Rohan", "kaushik@outlook.com"],
]
Output: [
["Rohan", "rohan123@gmail.com", "1279ro@gmail.com", "niemann01@gmail.com"],
["Rohit", "rohit101@yahoo.com", "hitman30487@gmail.com"],
["Rohan", "kaushik@outlook.com"],
]
Explanation: The first and third "Rohan" are the same person as they have a shared email address, “1279ro@gmail.com”. The rest of the accounts are of different persons, as they don’t share any shared email addresses. So, we merge the first and third accounts.
First I gave the map-based approach but that approach failed in some test cases.
Finally, I gave DSU based solution.

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