Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: A pair of ropes is connected as a chain: lengths 3, 4, 5 are joined in the order listed, each join costs the sum of the two lengths being joined, and the joined rope then acts as one piece. What is the total cost of joining 3 and 4 first, then the result with 5?
- A. 12
- B. 21
- C. 24
- D. 19
Correct answer: D. 19
Join 3 + 4 = 7 (cost 7), then 7 + 5 = 12 (cost 12): total 19. Counting only the last join gives 12, joining 4 and 5 first gives 9 + 12 = 21, and 24 adds the total length twice.
More Coding Interview Problems questions
- Problem: From the list [5, 3, 3, 7, 12, 9], what is the second-smallest distinct value (duplicates count once)?
- Problem: In the array [1, −2, 3, −4, 5, −6], how many contiguous subarrays have a sum of exactly 0?
- Problem: The mapping of letters is A=1 through Z=26. What is the sum of the values of the letters in the word "MATH"?
- Problem: The number of ways to choose 4 people from 9 so that a specific two people are never both chosen is what value?
- Problem: How many integers in [1, 10^4] are divisible by 3 and have an odd number of digits? Run the code. python print(sum(1 for x in…
- Problem: What is the number of distinct subsets sums obtainable from {2, 3, 7} (including the empty subset)? Run the code. python from…