Add office photos
Engaged Employer

Sigmoid

3.3
based on 103 Reviews
Filter interviews by

Petrofab Engineering Interview Questions and Answers

Updated 23 Sep 2024
Popular Designations
Q1. Next Greater Element

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

Ans.

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.

View 4 more answers
Q2. Search In Rotated Sorted Array

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

Ans.

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.

View 2 more answers
Q3. K-th element of 2 sorted array

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

Ans.

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

View 3 more answers
Q4. Zigzag Binary Tree Traversal

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

Ans.

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

View 1 answer
Discover Petrofab Engineering interview dos and don'ts from real experiences

Q5. check if there is a loop in linked list

Ans.

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.

Add your answer

Q6. Matrix traversal in spiral Manner

Ans.

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.

Add your answer

Q7. Sortr an array of 0,1

Ans.

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']

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

Interview Process at Petrofab Engineering

based on 3 interviews in the last 1 year
1 Interview rounds
Coding Test Round
View more
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top Data Engineer Interview Questions from Similar Companies

3.8
 • 40 Interview Questions
3.2
 • 16 Interview Questions
3.0
 • 12 Interview Questions
3.4
 • 12 Interview Questions
3.5
 • 11 Interview Questions
4.0
 • 11 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
Get AmbitionBox app

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