Sigmoid
50+ UB Engineering 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. Given a non-decreasing array, how can I determine the indices of an element X within it? If the element is not present, the output should be [-1, -1]. For example, for the array [1,2,3,3,5,5,7,8] and X=5, the e...
read moreFind indices of an element in a non-decreasing array
Iterate through the array and keep track of the indices where the element X is found
Return the list of indices or [-1, -1] if element X is not found
Handle edge cases like empty array or X not present in the array
Q6. How you will figure out how many WhatsApp user are there in world
Estimating the number of WhatsApp users worldwide requires a combination of data sources and statistical methods.
Collect data from WhatsApp's official reports and announcements
Use third-party analytics tools to estimate user numbers
Analyze demographic and geographic trends to extrapolate global user numbers
Consider factors such as population growth and smartphone adoption rates
Compare with similar messaging apps to validate estimates
Q7. Tell me about the how you will tackle a crude data for data analysis
I will start by understanding the data source and its quality, then clean and preprocess the data before performing exploratory data analysis.
Understand the data source and its quality
Clean and preprocess the data
Perform exploratory data analysis
Identify patterns and trends in the data
Use statistical methods to analyze the data
Visualize the data using graphs and charts
Iterate and refine the analysis as needed
Q8. in an integer array where element represent stock price and index represent days how to detect the best day to buy and best day to sell in O(N)
To detect the best day to buy and sell stock in an integer array representing stock prices and days in O(N).
Iterate through the array and keep track of the minimum price seen so far.
Calculate the profit by subtracting the current price from the minimum price.
Update the maximum profit and best buy/sell days accordingly.
Return the best buy and sell days to maximize profit.
Q9. 1 - where is bean annotation used in springboot ?... In class or method
Bean annotation is used in Spring Boot on class or method to indicate that a method produces a bean to be managed by the Spring container.
Bean annotation is used on methods within a class to indicate that the method produces a bean to be managed by the Spring container.
It can also be used at the class level to indicate that the class itself is a Spring bean.
For example, @Bean annotation can be used on a method that creates and returns a DataSource bean in a configuration clas...read more
Q10. Find sum elements which will appear from left view of Binary tree
Calculate the sum of elements visible from the left view of a binary tree.
Traverse the binary tree from left to right and keep track of the first element seen at each level.
Add up the values of the first elements seen at each level to get the sum.
Q11. which access modifier to restrict interface method access to only derived or implemented classes
Protected access modifier restricts interface method access to only derived or implemented classes.
Use 'protected' access modifier to restrict access to only derived or implemented classes
Protected members are accessible within the same package or by subclasses
Example: 'protected void methodName() {}' in an interface
Q12. What do you understand about sigmoid
Sigmoid is a mathematical function that maps any real-valued number to a value between 0 and 1.
Sigmoid function is commonly used in machine learning and artificial neural networks.
It is an S-shaped curve that starts at 0 and approaches 1 as the input value increases.
The function is defined as f(x) = 1 / (1 + e^(-x)), where e is the base of the natural logarithm.
Sigmoid function is used for binary classification problems, where the output is either 0 or 1.
It is also used as an...read more
Q13. How would you deal with datasets having lots of categories
Utilize feature engineering techniques like one-hot encoding or target encoding to handle datasets with many categories.
Use feature engineering techniques like one-hot encoding to convert categorical variables into numerical values
Consider using target encoding to encode categorical variables based on the target variable
Apply dimensionality reduction techniques like PCA or LDA to reduce the number of features
Use tree-based models like Random Forest or XGBoost which can handle...read more
Q14. Given a binary string,find out the max length of substring having equal number of 1 and 0
Find max length of substring with equal 1s and 0s in a binary string.
Use a hash table to store the difference between the count of 1s and 0s seen so far.
If the difference is 0, update the max length seen so far.
If the difference is already in the hash table, update the max length using the current index and the index where the difference was first seen.
Return the max length.
Example: '1100010110' -> 8
Q15. How does dropout help in neural networks?
Dropout helps prevent overfitting in neural networks by randomly setting a fraction of input units to zero during training.
Dropout helps in preventing overfitting by reducing the interdependence between neurons
It acts as a regularization technique by randomly setting a fraction of input units to zero during training
Dropout forces the network to learn redundant representations, making it more robust and generalizable
It can be applied to different layers of the neural network t...read more
Q16. how does one services interact with other in microservice
Microservices interact with each other through APIs, messaging, or events.
Microservices communicate with each other through APIs, which can be synchronous or asynchronous.
Messaging systems like RabbitMQ or Kafka can be used for communication between microservices.
Events can be used for loosely coupled communication between microservices.
Service discovery mechanisms like Eureka or Consul help microservices locate and communicate with each other.
API gateways can be used to mana...read more
Q17. inferschema in pyspark when reading file
inferschema in pyspark is used to automatically infer the schema of a file when reading it.
inferschema is a parameter in pyspark that can be set to true when reading a file to automatically infer the schema based on the data
It is useful when the schema of the file is not known beforehand
Example: df = spark.read.csv('file.csv', header=True, inferSchema=True)
Q18. in an integer array find the next greatest number for all and display in O(N)
Find the next greatest number for each integer in an array in O(N) time complexity.
Iterate through the array from right to left
Use a stack to keep track of potential next greatest numbers
Pop elements from the stack that are less than the current element and update their next greatest number to the current element
Push the current element onto the stack
Repeat until all elements have a next greatest number
Q19. NextGreater element in array using Stack(can find on leetcode)
Using a stack to find the next greater element in an array of strings.
Iterate through the array from right to left.
Push elements onto the stack and compare with the top element to find the next greater element.
Pop elements from the stack until a greater element is found or stack is empty.
Q20. How does xgboost deal with nan values?
XGBoost can handle missing values (NaN) by assigning them to a default direction during tree construction.
XGBoost treats NaN values as missing values and learns the best direction to go at each node to handle them
During tree construction, XGBoost assigns NaN values to the default direction based on the training data statistics
XGBoost can handle missing values in both input features and target variables
Q21. what is data engineering
Data engineering is the process of designing, building, and managing the infrastructure and systems that enable the collection, storage, processing, and analysis of large volumes of data.
Data engineering involves creating and maintaining data pipelines
It focuses on data integration, transformation, and storage
Data engineers work with tools like Hadoop, Spark, and SQL
They ensure data quality, scalability, and reliability
Examples include building a data warehouse, designing ETL...read more
Q22. Find peak element in rotated sorted array
Peak element in rotated sorted array is found using binary search.
Use binary search to find the peak element in rotated sorted array.
Compare mid element with its neighbors to determine if it is a peak.
Adjust the search space based on comparison results.
Q23. Find k min elements in given array.
Find k min elements in given array.
Sort the array and return the first k elements.
Use a min heap of size k to find the k min elements.
Use quickselect algorithm to find the kth smallest element and return first k elements smaller than it.
Q24. 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.
Q25. what is scd in dw?
SCD stands for Slowly Changing Dimension in Data Warehousing.
SCD is a technique used in data warehousing to track changes to dimension data over time.
There are different types of SCDs - Type 1, Type 2, and Type 3.
Type 1 SCD overwrites old data with new data, Type 2 creates new records for changes, and Type 3 maintains both old and new values in separate columns.
Example: In a customer dimension table, if a customer changes their address, a Type 2 SCD would create a new record ...read more
Q26. Leetcode's sort 0 1 array in place
Sort an array of 0s and 1s in place without using extra space.
Use two pointers approach - one for 0s and one for 1s.
Swap elements at the two pointers until all 0s are on the left and 1s on the right.
Q27. Find that given tree is BST or not.
Check if a given tree is a Binary Search Tree (BST) or not.
Traverse the tree in-order and check if the elements are in ascending order.
Check if the maximum value in the left subtree is less than the root and the minimum value in the right subtree is greater than the root.
Use recursion to check if all subtrees are BSTs.
Time complexity: O(n), Space complexity: O(h) where h is the height of the tree.
Q28. Find pair in BST with given sum
Given a BST and a sum, find a pair of nodes whose values add up to the given sum.
Traverse the BST in-order and store the nodes in a list
Use two pointers approach to find the pair with the given sum
If the sum is less than the current pair, move the right pointer to the left
If the sum is greater than the current pair, move the left pointer to the right
If the sum is equal to the current pair, return the pair
Time complexity: O(n), Space complexity: O(n)
Q29. optimizing techniques in spark
Optimizing techniques in Spark involve partitioning, caching, and tuning resources for efficient data processing.
Use partitioning to distribute data evenly across nodes for parallel processing
Cache frequently accessed data in memory to avoid recomputation
Tune resources such as memory allocation and parallelism settings for optimal performance
Q30. repartition vs coalesce
Repartition is used to increase the number of partitions in a DataFrame, while coalesce is used to decrease the number of partitions.
Repartition involves shuffling data across the network, which can be expensive in terms of performance and resources.
Coalesce is a more efficient operation as it minimizes data movement by only merging existing partitions.
Repartition is typically used when there is a need for more parallelism or to evenly distribute data for better performance.
C...read more
Q31. normalization in db and types
Normalization in databases is the process of organizing data in a database to reduce redundancy and improve data integrity.
Normalization is used to eliminate redundant data and ensure data integrity.
It involves breaking down a table into smaller tables and defining relationships between them.
There are different normal forms such as 1NF, 2NF, 3NF, and BCNF.
Normalization helps in reducing data redundancy and improving query performance.
Example: In a database, instead of storing...read more
Q32. transformation vs action
Transformation involves changing the data structure, while action involves performing a computation on the data.
Transformation changes the data structure without executing any computation
Action performs a computation on the data and triggers the execution
Examples of transformation include map, filter, and reduce in Spark or Pandas
Examples of action include count, collect, and saveAsTextFile in Spark
Q33. Python programming how to count vowels
Python program to count vowels in a given string
Iterate through the string and check if each character is a vowel (a, e, i, o, u)
Increment a counter for each vowel found
Return the total count of vowels
Q34. Print the pascal triangle pattern
The Pascal triangle pattern is a triangular array of binomial coefficients.
Use a 2D array to store the values of the Pascal triangle.
Each value in the triangle is the sum of the two values above it in the previous row.
Print the values in a formatted manner to display the Pascal triangle pattern.
Q35. What is Data science?
Data science is a field that uses scientific methods, algorithms, and systems to extract knowledge and insights from structured and unstructured data.
Data science involves collecting, analyzing, and interpreting large amounts of data to solve complex problems.
It combines statistics, machine learning, and domain knowledge to make predictions and decisions.
Data scientists use programming languages like Python and R, as well as tools like SQL and Hadoop.
Examples of data science ...read more
Q36. Code in SQL and python(moderate)
The candidate is asked to code in SQL and Python at a moderate level.
Use SQL to query data from databases
Use Python to manipulate and analyze data
Practice writing SQL queries and Python scripts
Q37. System Design and hr principles
System design involves creating a high-level architecture of a software system, while HR principles focus on managing people effectively.
System design involves identifying components, defining their interactions, and ensuring scalability and reliability.
HR principles include hiring the right talent, providing training and development opportunities, and fostering a positive work culture.
Both system design and HR principles aim to optimize performance and achieve organizational...read more
Q38. how to install operating system
To install an operating system, you need to boot from installation media and follow the on-screen instructions.
Create a bootable installation media (USB, DVD, etc.)
Insert the installation media into the computer
Boot the computer from the installation media
Follow the on-screen instructions to select language, partition the disk, and install the OS
Reboot the computer after installation is complete
Q39. Validate binary search tree.
Validate if a binary tree is a binary search tree
In-order traversal should result in a sorted array
Check if each node's value is within the correct range
Recursively validate left and right subtrees
Q40. Reverse K group linked list.
Reverse K group linked list
Iterate through the linked list in groups of size K
Reverse each group of K nodes
Connect the reversed groups back together
Q41. Nearest Left Greater element.
Find the nearest element on the left side of an array that is greater than the current element.
Iterate through the array from right to left.
Use a stack to keep track of elements that are greater than the current element.
Pop elements from the stack until finding a greater element or the stack is empty.
If a greater element is found, that is the nearest left greater element.
If the stack is empty, there is no nearest left greater element.
Q42. rank vs dense rank
Rank assigns unique ranks to each distinct value, while dense rank assigns ranks without gaps.
Rank function assigns unique ranks to each distinct value in a result set.
Dense rank function assigns ranks to rows in a result set without any gaps between the ranks.
Rank function may skip ranks if there are ties in values, while dense rank will not skip ranks.
Q43. What is Decision Tree
A decision tree is a flowchart-like structure in which each internal node represents a test on an attribute, each branch represents the outcome of the test, and each leaf node represents a class label.
Decision trees are a popular machine learning algorithm used for classification and regression tasks.
They are easy to interpret and visualize, making them useful for understanding the decision-making process.
Each internal node in a decision tree represents a decision based on a ...read more
Q44. 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.
Q45. Currying with arrow function
Currying is a technique in functional programming where a function with multiple arguments is transformed into a sequence of nested functions, each taking a single argument.
Currying can be achieved using arrow functions in JavaScript.
Arrow functions automatically bind 'this' and do not have their own 'this' value.
Example: const add = a => b => a + b;
Example: const addFive = add(5); const result = addFive(3); // result will be 8
Q46. Design Custom Hashmap
Custom implementation of HashMap in Java
Use an array of linked lists to handle collisions
Implement methods like put, get, remove, containsKey, and size
Handle resizing of the hashmap when load factor exceeds a certain threshold
Q47. Leetcode's Maximum Path Sum
Find the maximum path sum in a binary tree
Use recursion to traverse the binary tree and calculate the maximum path sum at each node
At each node, calculate the maximum path sum that includes the current node and return the maximum path sum that does not include the current node
Update a global variable to keep track of the maximum path sum found so far
Q48. Data analysis with statistical tools
Data analysis involves using statistical tools to analyze and interpret data.
Statistical tools help in summarizing and visualizing data
They can be used to identify patterns, trends, and relationships in the data
Common statistical tools include regression analysis, hypothesis testing, and clustering
Statistical tools help in making data-driven decisions and predictions
Q49. 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']
Q50. DSA problem - DFS in graphs
DFS (Depth First Search) is a graph traversal algorithm that explores as far as possible along each branch before backtracking.
DFS is implemented using a stack data structure or recursion.
It starts at a selected node and explores as far as possible along each branch before backtracking.
DFS can be used to find connected components, detect cycles, and solve maze problems.
Example: In a graph with nodes A, B, C, and edges (A, B), (B, C), DFS starting at node A would visit nodes A...read more
Q51. DSA problem - minimum stack
Implement a stack that supports push, pop, top, and retrieving the minimum element in constant time.
Use two stacks - one to store the actual elements and another to store the minimum values encountered so far.
When pushing an element, check if it is smaller than the current minimum and push it to the min stack if so.
When popping an element, check if it is the current minimum and pop from the min stack if so.
Top operation can be implemented by returning the top element of the m...read more
Q52. High Level System Design
High level system design involves creating an overview of the architecture and components of a software system.
Identify the main components of the system
Define the interactions between components
Consider scalability and performance requirements
Choose appropriate technologies and frameworks
Create a diagram to visualize the system architecture
Top HR Questions asked in UB Engineering
Interview Process at UB Engineering
Top Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month