Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: The string "aabbbcccc" is encoded by writing each letter followed by its count, e.g. "a2b3c4". What is the length of the encoded string?
- A. 9
- B. 6
- C. 3
- D. 18
Correct answer: B. 6
Each run contributes its letter and a one-digit count: a2 b3 c4 = 6 characters. 9 is the original length, 3 counts only the letters, and writing a letter-count pair for every character gives 18.
More Coding Interview Problems questions
- Problem: What is the number of inversions in the array [2, 5, 1, 4, 3]?
- Problem: The array [3, 7, 1, 9] is used to create all non-empty contiguous subarrays. How many of them have an odd sum?
- Problem: In the array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], find the number of pairs (i, j) with i < j whose product is a multiple of 12.
- Problem: How many 5-digit numbers (10000–99999) have digits that sum to exactly 6 and begin with the digit 1?
- Problem: A string of 6 characters is formed from the letters {a, b} such that no two adjacent characters are equal. How many such strings…
- Problem: The Euclidean distance squared between (1,2) and (4,6) is what integer?