Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: The array [7, 3, 9, 1, 5] is processed by a selection that finds the position of the maximum, removes it, and repeats. The removal order gives a list of values in decreasing order. What is the value removed second?
- A. 3
- B. 9
- C. 7
- D. 5
Correct answer: C. 7
Removals happen in order 9, 7, 5, 3, 1, so the second removed is 7. The original second element (also the second smallest) is 3, 9 is removed first, and 5 is removed third.
More Coding Interview Problems questions
- Problem: How many 4-digit numbers (1000–9999) are palindromes (read the same forwards and backwards in decimal)?
- Problem: The string "abcabcabc" has how many distinct substrings of length 3?
- Problem: What is the number of walks of length 4 that start and end at the same vertex in the complete graph K3 (vertices 0, 1, 2, each…
- Problem: How many integers in [1, 999] have digits that are strictly increasing (each digit larger than the previous)? Run the code…
- Problem: What is the sum of the first 50 terms of the sequence 1, 1, 2, 3, 5, ... (Fibonacci numbers F(1) to F(50), with F(1)=F(2)=1)? Run…
- Problem: How many pairs (i < j) of [2, 4, 6, 9, 12, 15] have gcd(ai, aj) = 3? Run the code. python from math import gcd a = [2, 4, 6, 9…