🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Approaching DSA Interview Problems: all 10 questions

Quiz: Approaching DSA Interview Problems · Question 8 of 10

What does this print? (code)

What does this print?

from bisect import bisect_left, bisect_right
s = sorted([30, 10, 20, 20, 40])
print(bisect_right(s, 20) - bisect_left(s, 15), bisect_right(s, 35) - bisect_left(s, 31))
  1. A.3 1
  2. B.2 1
  3. C.3 0
  4. D.2 0
Answer & explanation

Correct answer: 2 0

The values from 15 to 20 are the two 20s. No value lies between 31 and 35.

Can you get the rest right without peeking?

Take the timed Quiz: Approaching DSA Interview Problems quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →