Riverbed Technology
MG Motor Interview Questions and Answers
Q1. How will you rotate matrix by 90 degrees clockwise and anticlockwise?
To rotate a matrix by 90 degrees clockwise, transpose the matrix and then reverse each row. To rotate anticlockwise, reverse each row and then transpose.
Transpose the matrix by swapping elements at (i, j) with (j, i)
Reverse each row of the transposed matrix
To rotate anticlockwise, reverse each row of the original matrix and then transpose
Q2. Two lines with 10 and 12 points, how many triangles possible?
There are 3 possible triangles that can be formed using the two lines.
To form a triangle, we need three points.
With two lines, we have a total of four points.
By choosing any three points, we can form a triangle.
Therefore, there are 3 possible triangles.
Q3. If the element not present return the nearest element to it?
The question is asking for a solution to find the nearest element to a given element in an array.
Iterate through the array and calculate the absolute difference between each element and the given element.
Keep track of the minimum difference encountered and the corresponding element.
Return the element with the minimum difference as the nearest element.
Q4. Identify most recent duplicate ? {"google","yahoo","yahoo","google"}-both google and yahoo are repeated but google is first return index 3
Identify the most recent duplicate in an array of strings.
Iterate through the array and keep track of the indices of each string using a hashmap.
If a string is already present in the hashmap, update its index.
After iterating through the array, find the string with the highest index in the hashmap.
Q5. How will you compress images?(Told 3 methods)
There are three common methods to compress images: lossless compression, lossy compression, and resizing.
Lossless compression reduces file size without losing any image quality. Examples include PNG and GIF formats.
Lossy compression reduces file size by discarding some image data. Examples include JPEG format.
Resizing reduces file size by changing the dimensions of the image. It can be done manually or using image processing libraries.
Q6. Return the element k from a BST
The function should return the element k from a Binary Search Tree (BST).
Traverse the BST in-order and keep track of the current element
If the current element is equal to k, return it
If the current element is greater than k, move to the left subtree
If the current element is less than k, move to the right subtree
Repeat until the element is found or the entire tree is traversed
Top Software Engineer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month