Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: The sorted array [2, 4, 4, 4, 7, 9, 9, 12] is searched with bisect_left and bisect_right. What is bisect_right(a, 4) − bisect_left(a, 4)?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
bisect_right minus bisect_left counts the copies of a value in a sorted list. Here 4 occurs three times.
More Coding Interview Problems questions
- Problem: Compute (7^2026 + 11^2026) mod 1000, where ^ is exponentiation.
- Problem: Maximum number of non-overlapping meetings that can be held in one room, where a meeting is an interval [start, end) and two…
- Problem: How many contiguous subarrays of [3, -1, 4, -2, 5, -6, 2, 1] have sum at most 6 when the sum is computed over all non-empty…
- Problem: Longest substring without repeating characters of "pwwkewabcdbbxq". What is its length?
- Problem: Build a binary search tree by inserting 50, 30, 70, 20, 40, 60, 80, 35, 45, 65 in that order (duplicates are not inserted). Count…
- Problem: Starting from an empty tree of directed edges, a DAG has edges 0→1, 0→2, 1→3, 2→3, 2→4, 3→5, 4→5, 1→4. How many distinct directed…