Oracle
NTPC Interview Questions and Answers
Q1. 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
Find all pairs of elements in an array that add up to a given target.
Iterate through the array and store each element in a hashmap along with its index.
For each element, check if the target minus the element exists in the hashmap.
If found, print the pair of elements. If not found, print (-1, -1).
Q2. Bursting Balloons Problem
Given an array ARR
of size N
, where each element represents the height of a balloon. The task is to destroy all balloons by shooting arrows from left to right. When an arrow hits a bal...read more
Find the minimum number of arrows needed to burst all balloons by shooting arrows from left to right.
Sort the array in ascending order to make it easier to determine the minimum number of arrows needed.
Iterate through the sorted array and count the number of times the height decreases.
The count of height decreases plus 1 gives the minimum number of arrows needed to burst all balloons.
Q3. Validate BST Problem Statement
Given a binary tree with N
nodes, determine whether the tree is a Binary Search Tree (BST). If it is a BST, return true
; otherwise, return false
.
A binary search tree (BST) is a b...read more
Validate if a binary tree is a Binary Search Tree (BST) based on given properties.
Check if the left subtree of a node contains only nodes with data less than the node's data.
Verify if the right subtree of a node contains only nodes with data greater than the node's data.
Ensure that both the left and right subtrees are also binary search trees.
Iterate through the tree in level order form to validate the BST properties.
Q4. Construct Tree from Preorder Traversal
Given a list of integers pre[]
of size n
, representing the preorder traversal of a special binary tree where each node has 0 or 2 children, and a boolean array isLeaf[]
in...read more
Construct a binary tree from preorder traversal and leaf node information.
Create a binary tree using preorder traversal and leaf node information
Use recursion to build the tree
Handle both leaf and non-leaf nodes appropriately
Q5. Root to Leaf Path Problem Statement
Given a binary tree with 'N' nodes numbered from 1 to 'N', your task is to print all the root-to-leaf paths of the binary tree.
Input:
The first line of the input contains a ...read more
Given a binary tree, print all root-to-leaf paths in order.
Traverse the binary tree from root to leaf nodes, keeping track of the path nodes.
Use depth-first search (DFS) to explore all possible paths.
Return each path as a string of nodes separated by spaces.
Handle cases where nodes have NULL values by skipping them in the path.
Ensure the order of nodes in each path is maintained.
Q6. Triplets with Given Sum Problem
Given an array or list ARR
consisting of N
integers, your task is to identify all distinct triplets within the array that sum up to a specified number K
.
Explanation:
A triplet i...read more
Identify all distinct triplets within an array that sum up to a specified number.
Iterate through the array and use nested loops to find all possible triplets.
Check if the sum of the triplet equals the specified number.
Print the valid triplets or return -1 if no triplet exists.
Q7. Implement few design patterns
Implementing design patterns in software development
Singleton pattern ensures a class has only one instance and provides a global point of access to it
Factory pattern creates objects without specifying the exact class of object that will be created
Observer pattern defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated
More about working at Oracle
Interview Process at NTPC
Top Full Stack Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month