Data Structures & AlgorithmsModerateTCS NQT Digital · Accenture
Problem: The string "abcabc" is processed by replacing each character with its index in the alphabet (a=0, b=1, ..., z=25), and then the sum of the resulting numbers is computed. What is that sum?
- A. 12
- B. 3
- C. 6
- D. 588
Correct answer: C. 6
With a = 0, the letters give 0 + 1 + 2 + 0 + 1 + 2 = 6. Using a = 1 gives 12, processing only one "abc" gives 3, and summing ASCII codes gives 588.
More Coding Interview Problems questions
- Problem: A directed graph on vertices 0–4 has arcs 0→1 (2), 0→2 (6), 1→2 (3), 1→3 (9), 2→3 (1), 3→4 (2), 2→4 (8). What is the length of…
- Problem: Vertices 1–6 of an undirected graph have edges 1-2, 2-3, 4-5, 5-6, 6-4 and 3-1. How many edges are NOT part of any cycle?
- Problem: A rooted tree (root 1) has children 1: [2, 3], 2: [4], 3: [5, 6], 5: [7]. What is the number of nodes at depth 2 (root at depth 0)?
- Problem: The string "mississippi" contains repeated substrings. What is the length of the longest substring that appears at least twice…
- Problem: For the string "abcabcdab", how many substrings of length 3 occur exactly once?
- Problem: How many integers from 1 to 500 are NOT perfect squares and NOT perfect cubes?