Data Structures & AlgorithmsHardFlipkart/Uber OA · placement
Using a sliding window with a last-seen index map, what is the length of the longest substring of "dbcedadaadcced" with all characters distinct?
- A. 6
- B. 4
- C. 5
- D. 7
Correct answer: C. 5
When a repeat appears, move the left edge just past that character's previous occurrence (not to the current index). The best window has length 5. Restarting the window from scratch on a repeat gives 4.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Shell sort with gap sequence 4, 2, 1 (gapped insertion sort for each gap). What is the array after the gap-4 pass only? python a = [20…
- A 2-D array A[0..9][0..19] of 4-byte elements is stored in row-major order starting at address 1000. What is the address of A[7][7]?
- For each day, a monotonic stack finds how many days you must wait for a strictly warmer temperature (0 if never). What is printed? python…
- Delete every alternate node (2nd, 4th, …) of a linked list, then reverse what remains. What is printed? python def delalt(h): p = h while…
- How many contiguous subarrays of [5, 3, 4, 5, 1, 1, 6, 5] have a sum between 6 and 10 inclusive? (All values positive: count atMost(10) −…
- Keys 80, 42, 55, 92, 96, 24, 95, 69 are inserted in this order into an empty hash table of size 11 with h(k) = k mod 11 and linear…