← Arrays & Hashing Quiz: all 8 questions
Arrays & Hashing Quiz · Question 6 of 8
prefix = [0, 2, 5, 9, 14] for nums = [2, 3, 4, 5]. What is the sum of nums[1..3] (indices 1 to 3)?
prefix = [0, 2, 5, 9, 14] for nums = [2, 3, 4, 5]. What is the sum of nums[1..3] (indices 1 to 3)?
Answer & explanation
Correct answer: 12
Sum(l..r) = prefix[r+1] − prefix[l] = prefix[4] − prefix[1] = 14 − 2 = 12 (3 + 4 + 5).
Can you get the rest right without peeking?
Take the timed Arrays & Hashing Quiz quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →