Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
Under the hash h(s) = sum of the character codes of s, how many of the 3-letter strings "abc", "cab", "bac", "xyz", "zyx" share their hash with at least one other string in the list?
- A. 2
- B. 4
- C. 3
- D. 5
Correct answer: D. 5
Anagrams always share a sum-of-codes hash, so the three permutations of abc collide with one another, and xyz with zyx also collides. Counting those with a partner gives the answer.
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
- In 3 1 4 4 5 2 6 6 7, an element is a RECORD if it is strictly larger than every element before it (the first element is not counted). How…
- From the array 1 5 3 3 3 7 2 4 6, choose the largest number of PAIRS of positions so that every position is used in at most one pair and…
- What is the length of the longest contiguous subarray of 1 2 1 3 3 2 2 4 4 4 4 1 in which EVERY distinct value appears an even number of…
- Using only swaps of ADJACENT characters, what is the minimum number of swaps needed to turn the string "abcab" into a palindrome?
- From the string "aabbaabba" you may repeatedly delete any two ADJACENT characters that are different (one 'a' and one 'b'). What is the…
- For 5 2 7 1 4 6 3, how many split points i (0 ≤ i ≤ n−2) have XOR(A[0..i]) equal to XOR(A[i+1..n−1])?