Premium Employer

ServiceNow

4.2
based on 378 Reviews
Filter interviews by

20+ MN Dastur & Company Interview Questions and Answers

Updated 9 Jul 2024
Popular Designations

Q1. Set Matrix Zeros Problem Statement

Given an N x M integer matrix, if an element is 0, set its entire row and column to 0's, and return the matrix. Specifically, if a cell has a value 0 (i.e., matrix[i][j] == 0)...read more

View 2 more answers

Q2. Pascal's Triangle Problem Statement

You are provided with an integer N. The objective is to return a 2-dimensional list representing Pascal’s triangle up to row N.

A Pascal's triangle is a triangular array wher...read more

Add your answer

Q3. Pythagorean Triplets Detection

Determine if an array contains a Pythagorean triplet by checking whether there are three integers x, y, and z such that x2 + y2 = z2 within the array.

Input:

The first line contai...read more
Add your answer

Q4. K-th Smallest Element in BST

Your task is to find the ‘K-th’ smallest element in a given Binary Search Tree (BST).

Explanation:

A Binary Search Tree is a binary tree in which for each node, all elements in the ...read more

Add your answer
Discover MN Dastur & Company interview dos and don'ts from real experiences

Q5. Find product of each element of an array except that element in O(N) time complexity without using / operation

Ans.

Find product of each element of an array except that element in O(N) time complexity without using / operation

  • Use prefix and suffix products

  • Multiply prefix and suffix products for each element to get the final product

  • Handle edge cases where array has 0 or 1 element separately

Add your answer

Q6. Design a system for putting newspapers using classes and functions taking different aspects into account

Ans.

Design a system for putting newspapers using classes and functions

  • Create a Newspaper class with attributes like title, date, and content

  • Create a Publisher class with methods to publish and distribute newspapers

  • Create a Subscriber class with methods to subscribe and receive newspapers

  • Use inheritance to create different types of newspapers like daily, weekly, etc.

  • Implement a database to store newspaper information and handle subscriptions

Add your answer
Are these interview questions helpful?

Q7. Median of 2 sorted arrays in O(log N) time complexity and O(1) space complexity

Ans.

Find median of 2 sorted arrays in O(log N) time complexity and O(1) space complexity

  • Use binary search to find the partition point in both arrays

  • Calculate the median based on the partition point and array sizes

  • Adjust the partition points based on the median value

  • Repeat until the partition points are at the median

  • Handle edge cases such as empty arrays and uneven array sizes

Add your answer

Q8. Shortest path between 2 points in 2-D space in O(log N) time

Ans.

There is no known algorithm to find shortest path in 2-D space in O(log N) time.

  • The best known algorithm for finding shortest path in 2-D space is Dijkstra's algorithm which has a time complexity of O(N^2).

  • Other algorithms like A* and Bellman-Ford have better time complexity but still not O(log N).

  • If the points are on a grid, Lee algorithm can be used which has a time complexity of O(N).

Add your answer
Share interview questions and help millions of jobseekers 🌟

Q9. Reverse level order traversal of a tree using Queue

Ans.

Reverse level order traversal of a tree using Queue

  • Create a queue and push the root node into it

  • While the queue is not empty, pop the front node and push its children into the queue

  • Add the popped node to a stack

  • Once the queue is empty, pop elements from the stack and print them

Add your answer

Q10. Difference between Floyd Warshall and Djikstra

Ans.

Floyd Warshall finds shortest path between all pairs of vertices while Djikstra finds shortest path from a single source.

  • Floyd Warshall is used for dense graphs while Djikstra is used for sparse graphs.

  • Floyd Warshall has a time complexity of O(n^3) while Djikstra has a time complexity of O((n+m)logn).

  • Floyd Warshall can handle negative edge weights while Djikstra cannot.

  • Floyd Warshall can detect negative cycles while Djikstra cannot.

Add your answer

Q11. Level order traversal of a tree using Queue

Ans.

Level order traversal of a tree using Queue

  • Create a queue and add the root node to it

  • While the queue is not empty, remove the front node and print its value

  • Add the left and right child nodes of the removed node to the queue

  • Repeat until the queue is empty

Add your answer

Q12. Recursively deleting linked list from end

Ans.

Recursively delete a linked list from the end.

  • Start from the head and recursively traverse to the end of the list.

  • Delete the last node and set the second last node's next pointer to null.

  • Repeat until the entire list is deleted.

  • Use a recursive function to implement the deletion process.

Add your answer

Q13. Strings Anagram in O(1) space complexity

Ans.

Anagram of strings in O(1) space complexity

  • Use a fixed size array of integers to store the frequency of characters in the first string

  • Iterate through the second string and decrement the frequency of each character in the array

  • If all the frequencies are zero, then the strings are anagrams

  • Return true or false accordingly

Add your answer

Q14. BFS and DFS Difference

Ans.

BFS and DFS are graph traversal algorithms. BFS explores nodes level by level while DFS explores nodes depth by depth.

  • BFS uses a queue while DFS uses a stack or recursion.

  • BFS is optimal for finding shortest path while DFS is optimal for finding a path between two nodes.

  • BFS requires more memory as it stores all the nodes at each level while DFS requires less memory.

  • BFS can be used to find connected components while DFS can be used to detect cycles in a graph.

Add your answer

Q15. Recursively deleting linked list

Ans.

Recursively delete a linked list

  • Create a recursive function that takes the head of the linked list as input

  • Base case: if the head is null, return

  • Recursively call the function with the next node as input

  • Delete the current node

Add your answer

Q16. Write topological sort in directed acyclic graph

Ans.

Topological sort is a linear ordering of vertices in a directed acyclic graph where for every directed edge uv, vertex u comes before vertex v.

  • Create a list to store the topological ordering of vertices.

  • Find a vertex with no incoming edges and add it to the list.

  • Remove the vertex and its outgoing edges from the graph.

  • Repeat the process until all vertices are added to the list.

Add your answer

Q17. Recursively deleting from end

Ans.

Recursively delete elements from the end of an array.

  • Create a recursive function that removes the last element of the array.

  • Call the function recursively until the desired number of elements are removed.

  • Handle edge cases such as empty arrays and removing more elements than the array contains.

Add your answer

Q18. Recursively deleting tree

Ans.

Recursively delete a tree by deleting all its child nodes and then the parent node.

  • Start from the leaf nodes and delete them first.

  • Then move up to the parent nodes and delete them.

  • Repeat until the root node is deleted.

  • Use post-order traversal to ensure child nodes are deleted before parent nodes.

Add your answer

Q19. N meetings Find sub Array sum 0

Ans.

Given an array of N meetings, find a subarray with sum 0.

  • Use a hash table to store the cumulative sum of the array elements.

  • If the same sum is encountered again, it means the subarray between the two indices has a sum of 0.

  • Handle edge cases like when the subarray starts from index 0 or when the subarray ends at the last index.

Add your answer

Q20. write an algo for tower on hanoi in 7 steps

Ans.

The Tower of Hanoi is a classic problem that involves moving disks from one peg to another, following specific rules.

  • Start by moving the top n-1 disks from the source peg to the auxiliary peg.

  • Move the largest disk from the source peg to the target peg.

  • Move the n-1 disks from the auxiliary peg to the target peg.

  • Repeat the process recursively for the n-1 disks on the auxiliary peg.

  • Continue until all disks are moved to the target peg.

Add your answer

Q21. Low level Design of hashmap

Ans.

Hashmap is a data structure that stores key-value pairs and allows for quick retrieval of values based on keys.

  • Hashmap is typically implemented using an array of linked lists or a balanced binary search tree.

  • Each key is hashed to determine its index in the array, where the corresponding value is stored.

  • Collision handling is important in hashmap design to address cases where multiple keys hash to the same index.

  • Hashing function should be efficient to distribute keys evenly acr...read more

Add your answer
Contribute & help others!
Write a review
Share interview
Contribute salary
Add office photos

Interview Process at MN Dastur & Company

based on 10 interviews
3 Interview rounds
Resume Shortlist Round
Technical Round - 1
Technical Round - 2
View more
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top Software Engineer Interview Questions from Similar Companies

4.9
 • 21 Interview Questions
3.6
 • 20 Interview Questions
3.3
 • 12 Interview Questions
4.1
 • 11 Interview Questions
3.8
 • 10 Interview Questions
View all
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter