Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
How many index pairs i < j of [1, 2, 3, 4, 6, 6] satisfy a[i] * a[j] = a[i] + a[j]?
- A. 1
- B. 3
- C. 0
- D. 2
Correct answer: C. 0
The equation xy = x + y rewrites as (x-1)(y-1) = 1, so only (2,2) and (0,0) qualify. Here the single 2 cannot pair with itself, so the count is 0.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many distinct values v occur in [5, 1, 2, 3, 9, 10, 4] such that v + 1 also occurs in the array?
- Closed meeting intervals [1,3], [3,4], [2,5], [6,7] cannot share a room if they overlap even at one point. What is the minimum number of…
- How many inversions does the array [-3, -1, -2] have (pairs i < j with a[i] > a[j])?
- In "abcabdabc", how many positions i >= 1 start an occurrence of the prefix "abc" (the first three characters)?
- What is the sum of all integers from 1 to 50 inclusive that are coprime to 50?
- Let L be the length of the longest common subsequence of "ABCBDAB" and "BDCABA". How many different index-selections in "ABCBDAB" give a…