Data Structures & AlgorithmsModerateCodeforces Div2 B-D · ICPC regional
For "abcdab", list the five length-2 substrings and hash each as (ord(first) + ord(second)) mod 11. How many index pairs i < j have equal hash values?
- A. 2
- B. 3
- C. 4
- D. 8
Correct answer: A. 2
Compute the five hashes and count equal pairs. Equal substrings always share a hash, but the count also includes unequal substrings that collide.
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
- Arrivals at times 1, 2, 3, 5 and departures at 2, 4, 5, 6 (each arrival pairs with a departure; a train leaving at time t frees its…
- Take the XOR of a[i] XOR a[j] over all pairs i < j in [1, 2, 3, 4]. How many set bits (1-bits) does this combined XOR have?
- How many index triples i < j < k in [1, 2, 3, 4, 5, 6] satisfy a[i] + a[j] = a[k]?
- What is the smallest positive integer k such that k! is divisible by 2^10 = 1024?
- What is the length of the longest contiguous subarray of [2, 3, 1, 2, 4, 3] whose sum is exactly 7?
- The array [5, 3, 8, 6, 2] must be split into exactly 2 contiguous groups, minimising the largest group sum. What is that minimum?