Sigmoid
Westside Interview Questions and Answers
Q1. 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
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.
Q2. Problem: Search In Rotated Sorted Array
Given a sorted array that has been rotated clockwise by an unknown amount, you need to answer Q
queries. Each query is represented by an integer Q[i]
, and you must determ...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.
Q3. K-th Element of Two Sorted Arrays
You are provided with two sorted arrays, arr1
and arr2
, along with an integer k
. By merging all elements from arr1
and arr2
into a new sorted array, your task is to identify th...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
Q4. Zigzag Binary Tree Traversal Problem Statement
Determine the zigzag level order traversal of a given binary tree's nodes. Zigzag traversal alternates the direction at each level, starting from left to right, th...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 Westside
Top Data Engineer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month