JPMorgan Chase & Co.
20+ Vertiv Interview Questions and Answers
Q1. Rectangle Counting on an N x N Chessboard
Given a positive integer N, determine the number of possible rectangles that can be formed on an N x N chessboard, excluding squares.
Input:
The first line contains an ...read more
Count the number of rectangles (excluding squares) that can be formed on an N x N chessboard.
Calculate total rectangles using formula N*(N+1)*M*(M+1)/4 where M = N-1
Subtract the number of squares (N*(N+1)*(2*N+1)/6) from total rectangles
Return the count modulo 1000000007 for each test case
Q2. Reverse Words in a String: Problem Statement
You are given a string of length N
. Your task is to reverse the string word by word. The input may contain multiple spaces between words and may have leading or trai...read more
Reverse words in a string word by word, removing leading/trailing spaces and extra spaces between words.
Split the input string by spaces to get individual words
Reverse the order of the words
Join the reversed words with a single space in between
Remove any leading or trailing spaces
Q3. Sudoku Solver Problem Statement
You are provided with a 9x9 2D integer matrix MAT
representing a Sudoku puzzle. The empty cells in the Sudoku are denoted by zeros, while the other cells contain integers from 1 ...read more
Implement a function to solve a Sudoku puzzle by filling empty cells with valid numbers.
Iterate through each empty cell and try filling it with a valid number (1-9) that satisfies Sudoku rules.
Use backtracking to backtrack and try different numbers if a cell cannot be filled with a valid number.
Check rows, columns, and 3x3 sub-grids to ensure each digit appears only once.
Recursively solve the puzzle until all empty cells are filled with valid numbers.
Q4. Fastest Horse Problem Statement
Given ‘N’ horses running in separate lanes, each horse's finish time is provided in an array. You are tasked to process 'Q' queries. For each query, determine the time taken by t...read more
Given finish times of horses, determine fastest horse in specified lane ranges for multiple queries.
Iterate through each query and find the minimum finish time within the specified range of horses.
Use a nested loop to handle multiple test cases and queries efficiently.
Ensure to handle edge cases like empty ranges or invalid inputs.
Consider using a data structure like arrays to store finish times and process queries.
Q5. Rearrange Words in a Sentence
You are provided with a sentence 'TEXT'. Each word in the sentence is separated by a single space, and the sentence starts with a capital letter. Your task is to rearrange the word...read more
Rearrange words in a sentence based on increasing order of their length.
Split the sentence into words and calculate the length of each word.
Sort the words based on their lengths in increasing order.
If two words have the same length, maintain their original order from the input sentence.
Q6. Sudoku Validity Problem Statement
You are provided with a 9 x 9 2D matrix MATRIX
containing digits (1-9) and empty cells indicated by 0.
Your task is to determine if there exists a method to fill all empty cell...read more
Check if a valid Sudoku solution exists for a given 9x9 matrix with empty cells.
Iterate through each row, column, and sub-matrix to ensure all digits from 1 to 9 appear exactly once.
Use sets to keep track of digits seen in each row, column, and sub-matrix.
If any digit is repeated in a row, column, or sub-matrix, return 'no'.
If all rows, columns, and sub-matrices pass the validity check, return 'yes'.
Q7. Kth Largest Number Problem Statement
You are given a continuous stream of numbers, and the task is to determine the kth largest number at any moment during the stream.
Explanation:
A specialized data structure ...read more
Design a data structure to find the kth largest number in a continuous stream of integers.
Design a specialized data structure to handle continuous stream of numbers
Implement add(DATA) function to add integers to the pool
Implement getKthLargest() function to retrieve the kth largest number
Maintain the pool of numbers and update it based on queries
Output the kth largest number for each Type 2 query
Q8. Intersection of Linked List Problem
You are provided with two singly linked lists containing integers, where both lists converge at some node belonging to a third linked list.
Your task is to determine the data...read more
Find the node where two linked lists merge.
Traverse both lists to find their lengths and the difference in lengths.
Move the pointer of the longer list by the difference.
Traverse both lists simultaneously until they meet at the merging node.
Q9. Distance Between Two Nodes in a Binary Tree
Given a binary tree and the values of two distinct nodes, determine the distance between these two nodes in the tree. The distance is defined as the minimum number of...read more
Calculate the distance between two nodes in a binary tree.
Traverse the tree to find the paths from the root to each node
Find the lowest common ancestor of the two nodes
Calculate the distance by adding the distances from the LCA to each node
Q10. Next Greater Number Problem Statement
Given a string S
which represents a number, determine the smallest number strictly greater than the original number composed of the same digits. Each digit's frequency from...read more
The task is to find the smallest number greater than the given number with the same set of digits.
Iterate from right to left to find the first digit that can be swapped with a smaller digit to make the number greater.
Swap this digit with the smallest digit to its right that is greater than it.
Sort all digits to the right of the swapped digit in ascending order to get the smallest number greater than the original.
If no such number exists, return -1.
Example: For input '56789', ...read more
Q11. Problem: Sort an Array of 0s, 1s, and 2s
Given an array/list ARR
consisting of integers where each element is either 0, 1, or 2, your task is to sort this array in increasing order.
Input:
The input starts with...read more
Sort an array of 0s, 1s, and 2s in increasing order.
Use a three-pointer approach to sort the array in a single pass.
Initialize three pointers for 0, 1, and 2 values and iterate through the array.
Swap elements based on the values encountered to achieve the sorted array.
Q12. Shortest Path in a Binary Matrix Problem Statement
Given a binary matrix of size N * M
where each element is either 0 or 1, find the shortest path from a source cell to a destination cell, consisting only of 1s...read more
Find the shortest path in a binary matrix from a source cell to a destination cell consisting only of 1s.
Use Breadth First Search (BFS) algorithm to find the shortest path.
Keep track of visited cells to avoid revisiting them.
Update the path length as you traverse the matrix.
Return -1 if no valid path exists.
Q13. Most Frequent Non-Banned Word Problem Statement
Given a paragraph consisting of letters in both lowercase and uppercase, spaces, and punctuation, along with a list of banned words, your task is to find the most...read more
Find the most frequent word in a paragraph that is not in the list of banned words.
Split the paragraph into words and convert them to uppercase for case-insensitivity.
Count the frequency of each word, excluding banned words.
Return the word with the highest frequency in uppercase.
Q14. Count Subarrays with Given XOR Problem Statement
You are given an array of integers ARR
and an integer X
. Your task is to determine the number of subarrays of ARR
whose bitwise XOR is equal to X
.
Example:
Input...read more
Count the number of subarrays in an array whose XOR is equal to a given value.
Iterate through the array and keep track of XOR values and their frequencies using a hashmap.
For each element, calculate the XOR with the previous elements to find subarrays with XOR equal to the given value.
Use the hashmap to efficiently count the number of subarrays with the desired XOR value.
Handle edge cases like XOR value being 0 separately.
Time complexity can be optimized to O(N) using a hashm...read more
Q15. Stack using Two Queues Problem Statement
Develop a Stack Data Structure to store integer values using two Queues internally.
Your stack implementation should provide these public functions:
Explanation:
1. Cons...read more
Implement a stack using two queues to store integer values with specified functions.
Use two queues to simulate stack operations efficiently.
Maintain the top element in one of the queues for easy access.
Ensure proper handling of edge cases like empty stack or invalid operations.
Example: Push elements 5, 10, 15; Pop element 15; Check top element 10; Check size of stack; Check if stack is empty.
Q16. Remove the Kth Node from the End of a Linked List
You are given a singly Linked List with 'N' nodes containing integer data and an integer 'K'. Your task is to delete the Kth node from the end of this Linked Li...read more
Implement a function to remove the Kth node from the end of a singly linked list.
Traverse the list to find the length 'N' of the linked list.
Calculate the position of the node to be removed from the beginning as 'N - K + 1'.
Traverse the list again and remove the node at the calculated position.
Q17. LRU Cache Problem Statement
Design and implement a data structure for the Least Recently Used (LRU) Cache to efficiently support the following operations:
get(key)
: Retrieve the value of the key if it exists i...read more
Design and implement a data structure for LRU Cache to efficiently support get and put operations.
Implement a doubly linked list to maintain the order of recently used keys.
Use a hashmap to store key-value pairs for quick access.
Update the linked list and hashmap accordingly for get and put operations.
Discard the least recently used item when the cache reaches its capacity.
Handle edge cases like key not found in cache.
Example: Initialize cache with capacity 3, perform get and...read more
Q18. Populating Next Right Pointers in Each Node
Given a complete binary tree with 'N' nodes, your task is to determine the 'next' node immediately to the right in level order for each node in the given tree.
Input:...read more
Implement a function to populate next right pointers in a complete binary tree.
Traverse the tree level by level using BFS
For each node, set its next pointer to the next node in the same level
Handle null nodes appropriately by setting next pointer to null
Ensure the tree is a complete binary tree to guarantee correct output
Q19. Pair Sum Problem Statement
You are given an integer array 'ARR' of size 'N' and an integer 'S'. Your task is to find and return a list of all pairs of elements where each sum of a pair equals 'S'.
Note:
Each pa...read more
Find pairs of elements in an array that sum up to a given value, sorted in a specific order.
Iterate through the array and for each element, check if the complement (S - current element) exists in a hash set.
If the complement exists, add the pair to the result list.
Sort the result list based on the criteria mentioned in the problem statement.
Q20. Longest Palindromic Substring Problem Statement
You are provided with a string STR
of length N
. The goal is to identify the longest palindromic substring within this string. In cases where multiple palindromic ...read more
Given a string, find the longest palindromic substring, choosing the one with the smallest start index if multiple exist.
Iterate through the string and expand around each character to find palindromes
Keep track of the longest palindrome found and its starting index
Return the longest palindromic substring with the smallest start index
Q21. Merge Two Sorted Linked Lists Problem Statement
You are provided with two sorted linked lists. Your task is to merge them into a single sorted linked list and return the head of the combined linked list.
Input:...read more
Merge two sorted linked lists into a single sorted linked list without using additional space.
Create a dummy node to start the merged list
Compare the values of the two linked lists and append the smaller value to the merged list
Move the pointer of the merged list and the pointer of the smaller value's linked list
Continue this process until one of the linked lists is fully traversed
Append the remaining elements of the other linked list to the merged list
More about working at JPMorgan Chase & Co.
Top HR Questions asked in Vertiv
Interview Process at Vertiv
Top Software Developer Intern Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month