Data Structures & AlgorithmsModerateTCS NQT · Infosys
Points (0,0), (1,2), (2,1), (3,3), (4,0) in the plane. How many unordered pairs have Manhattan distance exactly 3?
- A. 5
- B. 7
- C. 4
- D. 1
Correct answer: A. 5
Compute |dx| + |dy| for each of the ten unordered pairs and count the ones equal to 3. Euclidean distance of 3 is a different condition and gives another count.
More Coding Interview Problems questions
- Four sets {1,2,3}, {2,4}, {3,4,5}, {1,5} are given. How many non-empty sub-collections of these sets have a union equal to {1, 2, 3, 4, 5}?
- Problem: How many pairs of equal values (i < j, a[i] = a[j]) does a = [1, 2, 1, 3, 2, 2] contain? Run the code. python from collections…
- Problem: How many longest increasing subsequences does [1, 3, 5, 4, 7] have? Run the DP that counts both length and number of optimal…
- Problem: What is the largest number of distinct characters in any window of length 3 of 'abcabc'? Run the code. python s = 'abcabc'…
- Problem: How many distinct values does x XOR y take over pairs of distinct elements of [1, 2, 3]? Run the code. python from itertools…
- Problem: What does the following print? It sums the entries at even positions of the array sorted in descending order. python a = [5, 1…