PayPal
100+ Megha Engineering & Infrastructures Interview Questions and Answers
Q1. Painting Fences Problem Statement
You are given ‘N’ fences. Your task is to compute the total number of ways to paint these fences using only 2 colors, such that no more than 2 adjacent fences have the same col...read more
Q2. Cycle Detection in a Singly Linked List
Determine if a given singly linked list of integers forms a cycle or not.
A cycle in a linked list occurs when a node's next
points back to a previous node in the list. T...read more
Q3. Integer to Roman Conversion
Given an integer N
, convert it to its corresponding Roman numeral representation. Roman numerals comprise seven symbols: I, V, X, L, C, D, and M.
Example:
Input:
N = 2
Output:
II
Exp...read more
Q4. Reverse Linked List Problem Statement
Given a singly linked list of integers, return the head of the reversed linked list.
Example:
Initial linked list: 1 -> 2 -> 3 -> 4 -> NULL
Reversed linked list: 4 -> 3 -> 2...read more
Q5. Cycle Detection in Undirected Graph Problem Statement
You are provided with an undirected graph containing 'N' vertices and 'M' edges. The vertices are numbered from 1 to 'N'. Your objective is to determine whe...read more
Q6. Longest Repeating Subsequence Problem Statement
Given a string st
, your task is to determine the length of the longest repeating subsequence such that no two subsequences have the same character at the same pos...read more
Q7. Painter's Partition Problem
You are given an array/list of length 'N'. Each element of the array/list represents the length of a board. There are 'K' painters available to paint these boards. Each unit of a boa...read more
Q8. Maximum Path Sum in a Matrix
Given an N*M matrix filled with integer numbers, determine the maximum sum that can be obtained from a path starting from any cell in the first row to any cell in the last row.
You ...read more
Q9. Find Magic Index in Sorted Array
Given a sorted array A consisting of N integers, your task is to find the magic index in the given array, where the magic index is defined as an index i such that A[i] = i.
Exam...read more
Q10. Merge Sort Problem Statement
You are given a sequence of numbers, ARR
. Your task is to return a sorted sequence of ARR
in non-descending order using the Merge Sort algorithm.
Explanation:
The Merge Sort algorit...read more
Q11. Palindrome Partitioning II Problem Statement
Given a string ‘str’, find the minimum number of partitions needed such that every segment of the string is a palindrome.
The task is to make cuts in the string to p...read more
Q12. Sum Queries in a Sorted Array
Given two arrays arr
and queries
, your task is to determine the sum of all elements in arr
that are less than or equal to each element in queries
. The array arr
is provided in sort...read more
Q13. Friends Pairing Problem
The task is to determine the total number of ways to pair up 'N' friends or leave some of them single, following these rules:
- Each friend can either pair with one other friend or stay s...read more
Q14. Cycle Detection in a Directed Graph
Determine if a given directed graph contains a cycle. Return true
if at least one cycle is found, otherwise return false
.
Input:
T
The first line consists of the integer T, re...read more
Q15. Design a Constant Time Data Structure
Create a data structure that maintains mappings between keys and values, supporting the following operations in constant time:
1. INSERT(key, value): Add or update the inte...read more
Q16. Minimum Character Deletion Problem Statement
You have been provided a string STR
. Your task is to find and return the minimum number of characters that need to be deleted from STR
so that each character's frequ...read more
Q17. Count Ways To Reach The N-th Stair Problem Statement
You are given a number of stairs, N
. Starting at the 0th stair, you need to reach the Nth stair. Each time you can either climb one step or two steps. You ha...read more
Q18. K Largest Elements Problem Statement
Given an unsorted array containing 'N' integers, you are required to find 'K' largest elements from the array and return them in non-decreasing order.
Input:
The first line ...read more
Q19. Reverse the String Problem Statement
You are given a string STR
which contains alphabets, numbers, and special characters. Your task is to reverse the string.
Example:
Input:
STR = "abcde"
Output:
"edcba"
Input...read more
Q20. Total Area of Overlapping Rectangles Problem Statement
Determine the total area covered by two given rectangles on a 2-D coordinate plane, which may have an overlapping area.
Input:
The first line contains an i...read more
Q21. Maximum Difference Problem Statement
Given an array ARR
of N
elements, your task is to find the maximum difference between any two elements in ARR
.
If the maximum difference is even, print EVEN; if it is odd, p...read more
Q22. Sort Linked List Based on Actual Values
Given a Singly Linked List of integers that are sorted based on their absolute values, the task is to sort the linked list based on the actual values.
The absolute value ...read more
Q23. Rearrange String Problem Statement
Given a string ‘S’, your task is to rearrange its characters so that no two adjacent characters are the same. If it's possible, return any such arrangement, otherwise return “...read more
Q24. DFS Traversal Problem Statement
Given an undirected and disconnected graph G(V, E)
, where V
is the number of vertices and E
is the number of edges, the connections between vertices are provided in the 'GRAPH' m...read more
Q25. One Away Transformation Problem
Given two strings, A
and B
, determine whether A
can be transformed into B
by performing at most one of the following operations (including zero operations):
1. Delete a character...read more
Q26. Subset Sum Equal To K Problem Statement
Given an array/list of positive integers and an integer K, determine if there exists a subset whose sum equals K.
Provide true
if such a subset exists, otherwise return f...read more
Q27. Find The Sum Of The Left Leaves Problem Statement
Given a binary tree with ‘root’, your task is to find and return the sum of all the left leaf nodes.
Example:
Input:
1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1
Outpu...read more
Q28. Median of Two Sorted Arrays
Given two sorted arrays A
and B
of sizes N
and M
, find the median of the merged array formed by combining arrays A
and B
. If the total number of elements, N + M
, is even, the median ...read more
Q29. Delete a Node from a Linked List
You are provided with a linked list of integers. Your task is to implement a function that deletes a node located at a specified position 'POS'.
Input:
The first line contains a...read more
Q30. Find K Closest Elements
Given a sorted array 'A' of length 'N', and two integers 'K' and 'X', your task is to find 'K' integers from the array closest to 'X'. If two integers are at the same distance, prefer th...read more
Q31. Problem: Sort an Array of 0s, 1s, and 2s
Given an array/list ARR
consisting of integers where each element is either 0, 1, or 2, your task is to sort this array in increasing order.
Input:
The input starts with...read more
Q32. N Queens Problem
Given an integer N
, find all possible placements of N
queens on an N x N
chessboard such that no two queens threaten each other.
Explanation:
A queen can attack another queen if they are in the...read more
Q33. Kth Largest Element Problem
Given an array containing N
distinct positive integers and a number K
, determine the Kth largest element in the array.
Example:
Input:
N = 6, K = 3, array = [2, 1, 5, 6, 3, 8]
Output...read more
Q34. BFS Traversal in a Graph
Given an undirected and disconnected graph G(V, E) where V vertices are numbered from 0 to V-1, and E represents edges, your task is to output the BFS traversal starting from the 0th ve...read more
Q35. Minimum Cost Path Problem Statement
Given an N x M
matrix filled with integers, determine the minimum sum obtainable from a path that starts at a specified cell (x, y)
and ends at the top left corner of the mat...read more
Q36. Counting Sort Problem Statement
Ninja is learning about sorting algorithms, specifically those that do not rely on comparisons. Can you help Ninja implement the counting sort algorithm?
Example:
Input:
ARR = {-...read more
Q37. Reverse Only Letters Problem Statement
You are given a string S
. The task is to reverse the letters of the string while keeping non-alphabet characters in their original position.
Example:
Input:
S = "a-bcd"
Ou...read more
Q38. Next Greater Element Problem Statement
You are given an array arr
of length N
. For each element in the array, find the next greater element (NGE) that appears to the right. If there is no such greater element, ...read more
Q39. Left View of a Binary Tree
Given a binary tree, your task is to print the left view of the tree. The left view of a binary tree contains the nodes visible when the tree is viewed from the left side.
Input:
The ...read more
Q40. Valid Parentheses Problem Statement
Given a string 'STR' consisting solely of the characters “{”, “}”, “(”, “)”, “[” and “]”, determine if the parentheses are balanced.
Input:
The first line contains an integer...read more
Q41. Find All Pairs Adding Up to Target
Given an array of integers ARR
of length N
and an integer Target
, your task is to return all pairs of elements such that they add up to the Target
.
Input:
The first line conta...read more
Q42. Remove Duplicates from String Problem Statement
You are provided a string STR
of length N
, consisting solely of lowercase English letters.
Your task is to remove all duplicate occurrences of characters in the s...read more
Q43. Group Anagrams Together
Given an array/list of strings STR_LIST
, group the anagrams together and return each group as a list of strings. Each group must contain strings that are anagrams of each other.
Example:...read more
Q44. Balanced Parentheses Combinations
Given an integer N
representing the number of pairs of parentheses, find all the possible combinations of balanced parentheses using the given number of pairs.
Explanation:
Con...read more
Q45. Input a file. Select first 3 lines of the file. Select the longest line and count the number of words in that line. It was easy. I used Java methods to solve the problem. I explained the logic and he accepted i...
read moreThe program reads a file and selects the first 3 lines. It then identifies the longest line and counts the number of words in that line.
Read the file using appropriate file handling methods
Store the first 3 lines in an array of strings
Iterate through the array to find the longest line
Count the number of words in the longest line using string manipulation methods
Q46. Palindrome Checker Problem Statement
Given an alphabetical string S
, determine whether it is a palindrome or not. A palindrome is a string that reads the same backward as forward.
Input:
The first line of the i...read more
Q47. Divide Two Integers Problem Statement
You are given two integers dividend
and divisor
. Your task is to divide the integers without using multiplication, division, and modular operators. Return the quotient afte...read more
Q48. Character Counting Challenge
Create a program that counts and prints the total number of specific character types from user input. Specifically, you need to count lowercase English alphabets, numeric digits (0-...read more
Q49. But amazon can do the search in O(n). Why it has to go for O(nk)? For data structures like Hash tables and for large data, n will be large. So O(nk) is better than O(n) (former n is smaller than latter n).
O(nk) is better than O(n) for large data and hash tables.
O(nk) is better because it takes into account the size of the data and the number of keys.
For large data and hash tables, the size of n will be large, making O(nk) more efficient.
O(n) assumes a constant number of keys, which may not be the case in practice.
Amazon may have chosen O(nk) for better scalability and performance.
Q50. Replace Spaces in a String
Given a string STR
consisting of words separated by spaces, your task is to replace all spaces between words with the characters "@40".
Input:
The first line contains an integer ‘T’ d...read more
Q51. When you search for a particular product in amazon, it displays some of the search results. But, only few particular products which are available in amazon are displayed, not all. How does this happen? I told M...
read moreAmazon displays only a subset of search results based on various factors like relevance, popularity, and user preferences.
Amazon uses algorithms to determine which products to display in search results.
Factors considered include product relevance, customer reviews, sales rank, and availability.
Machine learning techniques may be used to personalize search results based on user behavior and preferences.
Amazon also considers factors like seller reputation and fulfillment options...read more
Q52. There exists a 3x3 matrix, start from the first element reach the last element of the matrix, between each edges there exists a weight. Reach the destination such that the sum of weights should be small. It was...
read moreThe question is about finding the shortest path in a 3x3 matrix with weighted edges.
This is a graph traversal problem.
Use a graph algorithm like Dijkstra's algorithm or A* search to find the shortest path.
Assign weights to the edges and calculate the sum of weights for each possible path.
Choose the path with the smallest sum of weights as the shortest path.
Q53. Vertical Order Traversal Problem Statement
You are given a binary tree, and the task is to perform a vertical order traversal of the values of the nodes in the tree.
For a node at position ('X', 'Y'), the posit...read more
Q54. Dijkstra's Shortest Path Problem
Given an undirected graph with ‘V’ vertices (labeled 0, 1, ... , V-1) and ‘E’ edges, where each edge has a weight representing the distance between two connected nodes (X, Y).
Y...read more
Q57. Similar String Groups Problem Statement
Two strings S1
and S2
are considered similar if either S1
equals S2
or we can swap two letters of S1
at different positions so that it equals S2
.
Input:
The first line of...read more
Q58. How would I explain the concept of prime number to an illiterate?
A prime number is a number that is divisible only by 1 and itself.
A prime number has exactly two factors: 1 and itself.
Prime numbers cannot be divided evenly by any other number.
Examples of prime numbers include 2, 3, 5, 7, 11, 13, 17, etc.
Q59. What will be the key and what will be the values? The product will be the key. The brands will be the values.
The product will be the key and the brands will be the values.
The key in this case refers to the unique identifier for each product.
The values are the different brands associated with each product.
For example, if the product is a smartphone, the key could be the model number and the values could be the different brands that manufacture that model.
Q60. What js E cheque ? And what is the time for its clearance
An e-cheque is an electronic version of a paper cheque that is used for making payments online.
E-cheques are created and signed digitally, eliminating the need for physical paper.
They are typically used for online transactions and can be deposited into a bank account electronically.
The clearance time for e-cheques varies depending on the bank and the specific transaction.
It can take anywhere from a few hours to several business days for an e-cheque to clear.
During the clearan...read more
Q64. Five advantages of spring boot Which java version you currently use? Features of the java version you use Output from the code Difference between this and super In order to update the string, which will be bett...
read moreSpring Boot offers advantages like rapid development, easy configuration, embedded servers, production-ready features, and more.
Rapid development: Spring Boot simplifies the setup and configuration of Spring applications, allowing developers to focus on writing business logic.
Easy configuration: Spring Boot provides auto-configuration, reducing the need for manual setup and boilerplate code.
Embedded servers: Spring Boot comes with embedded servers like Tomcat, Jetty, and Unde...read more
Q65. Do you know Radix Sort? Where it is used? Radix sort can be applied in amazon.
Radix sort is a sorting algorithm that sorts integers by processing individual digits from least significant to most significant.
Radix sort is a non-comparative sorting algorithm.
It sorts numbers by grouping them based on each digit's value.
It is commonly used for sorting strings in lexicographic order.
Radix sort has linear time complexity, making it efficient for large datasets.
Q67. Suggest as many methods as possible for finding the nth largest element in an unsorted linked list
Methods to find nth largest element in an unsorted linked list
Traverse the linked list and store elements in an array, sort the array and return the nth largest element
Use quickselect algorithm to find the nth largest element in O(n) time complexity
Implement a max heap and extract the nth largest element
Divide the linked list into smaller sublists and recursively find the nth largest element
Use merge sort to sort the linked list and return the nth largest element
Q68. What data structure do they use? Hash tables.
Hash tables are a data structure that uses a hash function to map keys to values, providing efficient lookup, insertion, and deletion.
Hash tables use a hash function to convert keys into array indices.
They provide constant-time average case complexity for search, insert, and delete operations.
Collisions can occur when different keys map to the same index, which can be resolved using techniques like chaining or open addressing.
Examples of hash table implementations include Pyt...read more
Q70. what is hashing and how will you implement?
Hashing is a process of converting data into a fixed-size numerical value called a hash code.
Hashing is used to quickly retrieve data from large datasets.
It is commonly used in data structures like hash tables and hash maps.
Hash functions should be fast, deterministic, and produce unique hash codes for different inputs.
Examples of hash functions include MD5, SHA-1, and SHA-256.
Q71. Application of Fibonacci series in day-to-day life.
The Fibonacci series can be applied in day-to-day life for various purposes.
Financial planning: Fibonacci numbers can be used to calculate investment growth and determine optimal investment strategies.
Architecture and design: Fibonacci ratios can be used to create aesthetically pleasing designs and layouts.
Nature and biology: Fibonacci patterns can be observed in the growth of plants, arrangement of leaves, and formation of shells.
Music and art: Fibonacci sequences can be use...read more
Q73. Explain the concepts of Object Oriented Programming
Object Oriented Programming is a programming paradigm that uses objects to represent real-world entities.
Encapsulation: bundling data and methods that operate on that data within one unit
Inheritance: creating new classes from existing ones, inheriting their properties and methods
Polymorphism: ability of objects to take on multiple forms or behaviors
Abstraction: hiding complex implementation details and providing a simplified interface
Example: A car object can have properties ...read more
Q74. Design classes for educational institutions in a city
Design classes for educational institutions in a city
Identify the main entities: schools, students, teachers, courses
Create a School class with attributes like name, address, and a list of students and teachers
Create a Student class with attributes like name, age, and a list of courses
Create a Teacher class with attributes like name, specialization, and a list of courses
Create a Course class with attributes like name, duration, and a list of students and teachers
Establish rel...read more
Q75. no of pairs between 1 and N satisfy relation pow(a,3)+pow(b,3)=pow(c,3)+pow(d,3).a,b,c,d<=N
The question asks for the number of pairs between 1 and N that satisfy a specific mathematical relation.
The relation is pow(a,3) + pow(b,3) = pow(c,3) + pow(d,3)
The values of a, b, c, and d should be less than or equal to N
Count the number of pairs that satisfy the relation
Q76. find the and return if the given file path existing in the given file hierarcy(file system).
Check if a given file path exists in the file system hierarchy and return the result.
Use file system APIs to check if the given file path exists in the hierarchy.
Traverse the file system hierarchy starting from the root directory to find the given file path.
Return true if the file path exists, false otherwise.
Q77. Show the abstraction and write code for function overriding
Abstraction is hiding the implementation details, function overriding is providing a new implementation for a method in a subclass.
Abstraction involves hiding the complex implementation details and showing only the necessary features to the user.
Function overriding occurs in inheritance when a subclass provides a specific implementation for a method that is already defined in its superclass.
Example: Parent class 'Animal' has a method 'makeSound()', subclass 'Dog' overrides th...read more
Q78. Give a few test cases for a bank transaction
Test cases for a bank transaction
Transaction amount within account balance limit
Transaction amount exceeds account balance limit
Transaction to a valid account number
Transaction to an invalid account number
Transaction with correct transaction code
Transaction with incorrect transaction code
Transaction during bank working hours
Transaction outside bank working hours
Q79. Given an array of numbers find the subset of numbers that give zero sum.
Find subset of numbers in array that sum up to zero.
Use a nested loop to iterate through all possible subsets.
Calculate the sum of each subset and check if it equals zero.
Store the subset if the sum is zero.
Optimize the solution by using a hash set to store the cumulative sum of elements.
Q81. Optimal path cost and path in a matrix . Dynamic programming
Finding optimal path cost and path in a matrix using dynamic programming.
Dynamic programming is a technique to solve problems by breaking them down into smaller subproblems and solving them recursively.
In this case, we can use dynamic programming to find the optimal path cost and path in a matrix.
We can start by defining a 2D array to store the minimum cost of reaching each cell in the matrix.
Then, we can use a recursive function to calculate the minimum cost of reaching the ...read more
Q82. What you do if the customer is not happy for genivan cause?
Listen to their concerns, apologize, offer a solution, and follow up to ensure satisfaction.
Listen actively to their concerns and empathize with their situation.
Apologize for any inconvenience caused and take responsibility for the issue.
Offer a solution that addresses their concerns and meets their needs.
Follow up with the customer to ensure their satisfaction and address any further concerns.
Document the issue and the steps taken to resolve it for future reference.
Q83. Common puzzle- There are three boxes,one box of blue balls, one green and one mixed ,all labelled incorrectly. In how many trials will i label them correctly...
read moreThe boxes are labelled incorrectly with blue, green, and mixed balls. How many trials are needed to correctly label them?
Start by picking a ball from the box labelled 'mixed'. Since all labels are incorrect, this ball must be either blue or green.
Now, you can correctly label the box with the remaining two labels based on the color of the ball picked from the 'mixed' box.
This can be done in just one trial by picking a ball from the 'mixed' box.
Q84. A recursive program to print numbers in ascending order
A recursive program to print numbers in ascending order
Use a recursive function that takes a starting number and an ending number as parameters
Print the starting number and recursively call the function with starting number + 1 and the same ending number
Base case: stop recursion when starting number is greater than ending number
Q85. Program to implement Dijkstra’s algorithm
Dijkstra's algorithm finds the shortest path between nodes in a graph.
Create a graph with nodes and edges
Assign a tentative distance to each node
Set the initial node as current and mark it visited
For each neighbor of the current node, calculate the tentative distance
If the tentative distance is less than the current distance, update the distance
Mark the current node as visited and select the unvisited node with the smallest tentative distance
Repeat until the destination node ...read more
Q86. Running time of Radix sort? O(nk)
Radix sort has a running time of O(nk), where n is the number of elements and k is the length of the longest element.
Radix sort is a non-comparative sorting algorithm that sorts elements by their individual digits or characters.
It works by distributing the elements into 10 buckets based on the value of the least significant digit, then repeatedly redistributing them based on the next significant digit.
The process continues until all digits have been considered, resulting in a...read more
Q87. There are 10 weights of which two weigh less than the others. Using a balance how will i identify the defective ones...
read moreQ88. How many A4 sheets are sold in India per day?
It is impossible to accurately determine the number of A4 sheets sold in India per day.
There is no centralized data on the sales of A4 sheets in India.
The number of A4 sheets sold can vary greatly depending on the region and industry.
Factors such as digitalization and environmental concerns may also impact sales.
Estimates or projections may be available from specific companies or industries.
Market research firms may have data on the overall paper market in India.
Q89. Program to reverse a singly linked list
A program to reverse a singly linked list
Create a new empty linked list
Traverse the original linked list and insert each node at the beginning of the new list
Return the new list
Q90. Give examples of abstraction and polymorphism
Abstraction is hiding implementation details while polymorphism is using a single interface for multiple types.
Abstraction: Encapsulation, Interfaces, Abstract classes
Polymorphism: Method Overloading, Method Overriding, Interfaces
Abstraction Example: Car - we don't need to know how the engine works to drive it
Polymorphism Example: Animal - different animals have different sounds but they all have a 'makeSound' method
Q91. how to find cycle in graph
To find a cycle in a graph, use depth-first search (DFS) and keep track of visited nodes.
Implement DFS algorithm to traverse the graph
Maintain a visited array to keep track of visited nodes
If a visited node is encountered again during DFS, a cycle exists
Q92. What is shortest path problem ,and write a code for it
Shortest path problem is finding the shortest path between two nodes in a graph.
It is a common problem in graph theory and computer science.
Dijkstra's algorithm and Bellman-Ford algorithm are commonly used to solve it.
The problem can be solved using dynamic programming and graph traversal techniques.
Examples include finding the shortest route between two cities on a map or the shortest path for a robot to navigate a maze.
Q94. How will you track payment failure count and make it fail safe
Track payment failure count and ensure fail safe measures
Implement a system to track payment failure count in real-time
Set up alerts for payment failures exceeding a certain threshold
Automate retries for failed payments with back-off strategies
Implement logging and monitoring to track payment failure trends
Integrate with payment gateway APIs to handle failures gracefully
Q96. What are OOPS concepts like inheritance,polymorphism etc
Q97. What was my work and explain how did I work with data
I worked as a data analyst, collecting, cleaning, and analyzing data to identify trends and make recommendations.
Collected data from various sources such as databases, spreadsheets, and APIs
Cleaned and organized data to ensure accuracy and consistency
Performed statistical analysis to identify patterns and trends
Created visualizations and reports to communicate findings to stakeholders
Q98. What are the metrics that you are working on
I am currently working on metrics such as first call resolution, average handling time, and customer satisfaction.
First call resolution - ensuring that customer issues are resolved on the first call
Average handling time - tracking the time it takes to resolve customer issues
Customer satisfaction - measuring how satisfied customers are with the service provided
Top HR Questions asked in Megha Engineering & Infrastructures
Interview Process at Megha Engineering & Infrastructures
Top Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month