PhonePe
10+ CAMBAY POWER SERVICES Interview Questions and Answers
Q1. Form a Triangle Problem Statement
You are given an array of integers ARR
with a length of N
. Your task is to determine whether it's possible to construct at least one non-degenerate triangle using the values fr...read more
Determine if it's possible to form a non-degenerate triangle using array elements as sides.
Check if the sum of any two sides is greater than the third side to form a triangle.
If any such combination exists, return 'YES'; otherwise, return 'NO'.
Example: For input [3, 4, 5], sum of 3 + 4 > 5, so 'YES'. For [1, 10, 12, 30], no such combination exists, so 'NO'.
Q2. Minimum Moves to Collect All Keys
Given an 'N' x 'M' grid, find the minimum number of moves required to collect all keys when starting at a specified point. Each move allows you to travel to an adjacent cell (u...read more
Find the minimum number of moves required to collect all keys in a grid starting from a specified point.
Use breadth-first search (BFS) to explore all possible paths from the starting point to collect keys.
Keep track of keys collected, locks encountered, and the number of moves taken in each path.
Avoid revisiting cells, and consider the movement rules while traversing the grid.
Return the minimum number of moves to collect all keys, or -1 if it is impossible.
Q3. Unlock the Briefcase Problem Statement
You have a briefcase secured by a lock with 4 circular wheels. The password is a sequence of 4 digits. Each wheel has 10 slots labeled ‘0’ through ‘9’. The wheels can rota...read more
Find the minimum number of rotations required to unlock a briefcase with a given target code, considering dead-end codes.
Iterate through all possible combinations of rotations to find the shortest path to the target code.
Use a queue to efficiently explore all possible combinations.
If the target code is a dead-end code, return -1 as it is not feasible to unlock the briefcase.
Q4. Weighted Job Scheduling Problem Statement
You have 'N' jobs, each with a start time, end time, and profit. Your task is to identify the maximum profit that can be earned by scheduling these jobs such that no tw...read more
The Weighted Job Scheduling problem involves maximizing profit by scheduling non-overlapping jobs with start time, end time, and profit given.
Sort the jobs based on their end times in ascending order.
Initialize an array 'dp' to store the maximum profit that can be earned by scheduling jobs up to that index.
For each job, find the maximum profit by either including or excluding the current job based on non-overlapping condition.
Return the maximum profit from the 'dp' array.
Exam...read more
Q5. Max GCD Pair Problem Statement
Given an array of positive integers, determine the Greatest Common Divisor (GCD) of a pair of elements such that it is the maximum among all possible pairs in the array. The GCD o...read more
Find the maximum GCD of a pair of elements in an array of positive integers.
Iterate through all pairs of elements in the array
Calculate the GCD of each pair using Euclidean algorithm
Keep track of the maximum GCD found
Return the maximum GCD value
Q6. Best Time To Buy and Sell Stock Problem Statement
You are given an array 'PRICES' of 'N' integers, where 'PRICES[i]' represents the price of a certain stock on the i-th day. An integer 'K' is also provided, ind...read more
Determine the maximum profit achievable with at most K transactions by buying and selling stocks.
Iterate through the array and keep track of the minimum price to buy and maximum profit to sell.
Use dynamic programming to calculate the maximum profit with at most K transactions.
Consider edge cases like when K is 0 or when the array is empty.
Example: For input N = 6, PRICES = [3, 2, 6, 5, 0, 3], K = 2, the output should be 7.
Q7. Maximum Sum Rectangle Problem Statement
Given a matrix ARR
with dimensions N
x M
, your task is to identify the rectangle within the matrix that has the maximum sum of its elements.
Input:
The first line contain...read more
Find the rectangle with the maximum sum of elements in a given matrix.
Iterate through all possible rectangles in the matrix and calculate the sum of each rectangle.
Keep track of the maximum sum encountered so far.
Optimize the solution by using Kadane's algorithm for 1D array to find maximum sum subarray in each row.
Q8. Minimum Time to Burn a Binary Tree from a Leaf Node
You are given a binary tree with 'N' unique nodes, and a specific start node from where the fire will begin. The task is to determine the time in minutes requ...read more
The task is to determine the time in minutes required to burn the entire binary tree starting from a given node.
Traverse the tree from the given start node to calculate the time taken to burn the entire tree.
Use a queue to keep track of nodes and their burning time.
Increment the burning time for each level of nodes until the entire tree is burned.
Q9. Snake and Ladder Problem Statement
Given a 'Snake and Ladder' board with N rows and N columns, where positions are numbered from 1 to (N*N) starting from the bottom left, alternating direction each row, find th...read more
Find the minimum number of dice throws required to reach the last cell on a 'Snake and Ladder' board.
Use Breadth First Search (BFS) to find the shortest path from the starting cell to the last cell.
Keep track of visited cells and the number of dice throws required to reach each cell.
Consider the presence of snakes and ladders while calculating the next possible moves.
Return the minimum number of dice throws to reach the last cell, or -1 if unreachable.
Q10. Search In Rotated Sorted Array Problem Statement
Given a rotated sorted array ARR
of size 'N' and an integer 'K', determine the index at which 'K' is present in the array.
Note:
1. If 'K' is not present in ARR,...read more
Given a rotated sorted array, find the index of a given integer 'K'.
Use binary search to find the pivot point where the array is rotated.
Based on the pivot point, apply binary search on the appropriate half of the array to find 'K'.
Handle cases where 'K' is not present in the array by returning -1.
Q11. Knight Probability in Chessboard
Calculate the probability that a knight remains on an N x N chessboard after making K moves. Initially, the knight is placed at a given position on the board. It can move in any...read more
Calculate the probability that a knight remains on an N x N chessboard after making K moves.
Use dynamic programming to calculate the probability of the knight staying on the board after each move.
Consider all possible moves the knight can make from its current position.
Keep track of the probabilities at each position on the board after each move.
Normalize the probabilities at the end to get the final result.
Example: For a 3x3 board and 2 moves, the probability of the knight s...read more
Q12. Insertion in AVL Tree Problem Statement
You are required to implement an AVL Tree from scratch. Given 'N' values representing nodes, insert these values into the AVL Tree and return its root after all insertion...read more
Implement an AVL Tree from scratch and insert given values to balance the tree.
Implement AVL Tree with rotation operations for balancing.
Maintain balance factor for each node to ensure AVL property.
Perform rotations (single or double) based on balance factor to balance the tree.
Update heights of nodes after insertion to maintain AVL property.
Ensure tree remains balanced after each insertion operation.
Q13. Reverse the String Problem Statement
You are given a string STR
which contains alphabets, numbers, and special characters. Your task is to reverse the string.
Example:
Input:
STR = "abcde"
Output:
"edcba"
Input...read more
Reverse a given string containing alphabets, numbers, and special characters.
Iterate through the string from the end to the beginning and append each character to a new string.
Use built-in functions like reverse() or slicing to reverse the string.
Handle special characters and numbers while reversing the string.
Ensure to consider the constraints on the input string length and number of test cases.
Q14. Longest Increasing Subsequence Problem Statement
Given an array of integers with 'N' elements, determine the length of the longest subsequence where each element is greater than the previous element. This subse...read more
Find the length of the longest strictly increasing subsequence in an array of integers.
Use dynamic programming to solve this problem efficiently.
Initialize an array to store the length of the longest increasing subsequence ending at each index.
Iterate through the array and update the length of the longest increasing subsequence for each element.
Return the maximum value in the array as the result.
Q15. Selling Stock Problem Statement
You are given the stock prices for N
days. Each day i
signifies the price of a stock on that day. Your goal is to calculate the maximum profit that can be achieved by buying and ...read more
Calculate maximum profit by buying and selling stocks on different days.
Iterate through the stock prices and buy on the day when the price is lower than the next day's price, and sell on the day when the price is higher than the next day's price.
Keep track of the total profit earned by summing up the differences between buying and selling prices.
Return the total profit as the maximum profit that can be earned.
Q16. Longest Increasing Path in a 2D Matrix Problem Statement
Given a matrix of non-negative integers of size 'N x M', where 'N' and 'M' denote the number of rows and columns respectively, find the length of the lon...read more
Find the length of the longest increasing path in a 2D matrix by moving in four directions from each cell.
Use dynamic programming to keep track of the length of the longest increasing path starting from each cell.
Explore all four directions from each cell and recursively find the longest increasing path.
Optimize the solution by storing the length of the longest increasing path starting from each cell to avoid redundant calculations.
More about working at PhonePe
Interview Process at CAMBAY POWER SERVICES
Top Software Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month