Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
What is the number of unmatched '(' characters in the string "(()())(()" after the standard left-to-right matching?
- A. 2
- B. 0
- C. 1
- D. 4
Correct answer: C. 1
Scan with a counter: '(' increments, ')' decrements only when positive. The final counter is the number of unmatched openings.
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
- What is the largest number of distinct characters in any contiguous window of length 4 of "abcbdabca"?
- What is the sum of all positive divisors of 36?
- How many contiguous subarrays of [2, 4, 1, 3] have a sum in the inclusive range [4, 6]?
- How many distinct subsequences (including the empty string) does "aab" have?
- How many pairs (a, b) with 1 <= a <= b <= 20 satisfy a b = 36?
- For [4, 1, 3, 2, 5], each index i gets the index of its previous strictly greater element (or -1 if none). What is the sum of these values…