Data Structures & AlgorithmsModerateProduct Company SDE · CP practice
Problem: What is the sum of the ASCII codes of the characters of 'hello'? Run the code.
Problem: What is the sum of the ASCII codes of the characters of 'hello'? Run the code.
print(sum(ord(c) for c in 'hello'))What is printed?
- A. 532
- B. 372
- C. 52
- D. 424
Correct answer: A. 532
h, e, l, l, o have codes 104 + 101 + 108 + 108 + 111 = 532. Upper-case HELLO gives 372, alphabet positions give 52, and counting the repeated l once gives 424.
More Coding Interview Problems questions
- Problem: What is the length of the longest strictly increasing contiguous subarray of [3, 4, 5, 1, 2, 3, 4, 5, 6]? Run the code. python a…
- Problem: What is the minimum number of cuts needed to partition 'abcde' into palindromes? Run the DP. python s = 'abcde' n = len(s) pal =…
- Problem: How many two-digit numbers have a digit sum that is a prime number? Run the code. python def isp(n): return n > 1 and all(n % d…
- Problem: How many subarrays of [1, 2, 2, 3, 3, 3] have all equal maximum and minimum values? Run the code. python a = [1, 2, 2, 3, 3, 3]…
- Problem: How many integers in [1, 100] have exactly two prime factors counted with multiplicity? Run the code. python def omega(n): c = 0…
- Problem: What is the sum of all proper divisors of 220 (divisors smaller than 220)? Run the code. python print(sum(d for d in range(1…