Data Structures & AlgorithmsVery hardTCS NQT · Infosys
In the array [1, 4, 6, 8, 13], the minimum absolute difference between two distinct elements is d. How many index pairs i < j have |a[i] - a[j]| = d?
- A. 3
- B. 2
- C. 1
- D. 4
Correct answer: B. 2
After sorting, the minimum gap is 2 (6 to 8 and 4 to 6), so the pairs are counted by checking adjacent sorted values.
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 strings of length 4 over the alphabet {a, b} contain the letter a somewhere before a b (that is, contain 'a' followed later by…
- What is the edit distance (Levenshtein distance with insertion, deletion and substitution each costing 1) between intention and execution?
- What is the length of the longest common subsequence of AGGTAB and GXTXAYB (letters need not be contiguous)?
- What is the rank (1-based, in lexicographic order) of the string cab among all permutations of the letters a, b, c?
- How many trailing zeros does 2024! have in base 10?
- How many integers n with 2 <= n <= 200 are square-free (not divisible by the square of any integer greater than 1)?