Data Structures & AlgorithmsModerateAccenture · Infosys OA
Problem: Longest substring without repeating characters of "pwwkewabcdbbxq". What is its length?
- A. 8
- B. 5
- C. 10
- D. 7
Correct answer: D. 7
Jump the left edge to one past the previous occurrence (never backwards): the best window is 'kewabcd', length 7. Moving left only TO the previous occurrence keeps the duplicate and gives 8, restarting the window at the repeat gives 5, and counting distinct letters in the whole string gives 10.
More Coding Interview Problems questions
- 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…
- Problem: An MST is built with Kruskal's algorithm on vertices 0–4 and edges: 0-1 (4), 0-2 (1), 1-2 (2), 1-3 (5), 2-3 (8), 3-4 (3), 2-4…
- Problem: How many pairs (i, j) with i < j in the array [4, 8, 1, 5, 9, 2, 7, 3, 6] satisfy a[j] − a[i] = 3?
- Problem: How many contiguous subarrays of [7, 2, 9, 4, 1, 8, 3, 5, 6, 10] have a sum divisible by 7?
- Problem: Floyd–Warshall is run on 4 vertices with directed edges 0→1 (3), 1→2 (4), 0→2 (9), 2→3 (1), 3→0 (2), 1→3 (5). Unreachable pairs…