Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B
How many index pairs i < j in the array [1, 2, 3, 1, 2, 3] make a[i] * a[j] = 6?
- A. 4
- B. 5
- C. 3
- D. 6
Correct answer: A. 4
Products of 6 come from 2 with 3 and from 1 with 6 (absent here). Count the matching pairs by hashing the complement 6 / x for each x.
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 contiguous subarrays of [2, -2, 3, 1, -4, 2, -1] have sum 0?
- How many index pairs i < j in the array [1, 3, 5, 7, 2, 6, 8] have a[i] + a[j] equal to a power of 2?
- The string (()(()(( is scanned left to right: '(' opens and ')' closes the most recent unmatched '('. How many characters are unmatched in…
- What is the minimum number of brackets that must be inserted into ())(()(( to make it a balanced sequence?
- What is the length of the longest valid (well-formed) parentheses substring of )()())?
- Starting from an empty deque, the operations are: push front 1, push back 2, push front 3, pop back, push back 4. Let the deque contents…