Sigmoid
Petrofab Engineering Interview Questions and Answers
You are given an array arr of length N. You have to return a list of integers containing the NGE(next greater element) of each element of the given array. The NGE for an element X is the fir...read more
The task is to find the next greater element for each element in the given array.
Iterate through the array from right to left.
Use a stack to keep track of the next greater element.
Pop elements from the stack until a greater element is found or the stack is empty.
If the stack is empty, there is no greater element, so assign -1.
If a greater element is found, assign it as the next greater element.
Push the current element onto the stack.
Return the list of next greater elements.
Aahad and Harshit always have fun by solving problems. Harshit took a sorted array and rotated it clockwise by an unknown amount. For example, he took a sorted array = [1, 2, 3, 4,...read more
This is a problem where a sorted array is rotated and we need to search for given numbers in the array.
The array is rotated clockwise by an unknown amount.
We need to search for Q numbers in the rotated array.
If a number is found, we need to return its index, otherwise -1.
The search needs to be done in O(logN) time complexity.
The input consists of the size of the array, the array itself, the number of queries, and the queries.
You are given two sorted arrays/list ‘arr1’ and ‘arr2’ and an integer k. You create a new sorted array by merging all the elements from ‘arr1’ and ‘arr2’. Your task is to find the ...read more
The task is to find the kth smallest element of a merged array created by merging two sorted arrays.
Merge the two sorted arrays into a single sorted array
Return the kth element of the merged array
Given a binary tree, return the zigzag level order traversal of the nodes' values of the given tree. Zigzag traversal means starting from left to right, then right to left for the ne...read more
The zigzag level order traversal of a binary tree is the traversal of its nodes' values in an alternate left to right and right to left manner.
Perform a level order traversal of the binary tree
Use a queue to store the nodes at each level
For each level, alternate the direction of traversal
Store the values of the nodes in each level in separate arrays
Combine the arrays in alternate order to get the zigzag level order traversal
Q5. check if there is a loop in linked list
Check for a loop in a linked list by using two pointers moving at different speeds.
Use two pointers, one moving at a normal speed and another moving at double the speed.
If there is a loop, the two pointers will eventually meet at some point.
Alternatively, use a hash set to store visited nodes and check for duplicates.
Q6. Matrix traversal in spiral Manner
Matrix traversal in spiral manner involves visiting each element of a matrix in a spiral order.
Start by traversing the outermost layer of the matrix from top left to top right, then top right to bottom right, bottom right to bottom left, and finally bottom left to top left.
Continue this process for the inner layers until all elements are visited.
Keep track of the boundaries of the matrix to know when to switch directions.
Q7. Sortr an array of 0,1
Sort an array of 0s and 1s
Use a sorting algorithm like counting sort or two-pointer approach
Count the number of 0s and 1s and then reconstruct the array
Example: Input array = ['0', '1', '0', '1', '1'], Output array = ['0', '0', '1', '1', '1']
Interview Process at Petrofab Engineering
Top Data Engineer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month