Data Structures & AlgorithmsHardGATE CS · ICPC regional
Which algorithm computes the length of the longest increasing subsequence in O(n log n) time?
- A. Floyd-Warshall on the index graph
- B. Kruskal's minimum spanning tree
- C. Naive pairwise DP over all subsequences
- D. Patience sorting with binary search on the tails array
Correct answer: D. Patience sorting with binary search on the tails array
Maintain the smallest possible tail for each length and binary-search where a new value goes; the tails array's length is the LIS length.
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
- To count distinct values in every window of size k of an array in O(n) total time, which structure is most suitable?
- Stably sort the positions of -3 2 -2 1 3 -1 by the ABSOLUTE value of the element at each position (ascending), keeping the input order for…
- How many index pairs i < j in 1 3 2 5 4 6 8 satisfy A[j] − A[i] = j − i?
- For 3 1 4 1 5 9 2 6, find the smallest 0-based index t such that the sum of the elements A[0..t] is MORE than half of the total sum of the…
- A binary array of length 10^6 needs its longest contiguous subarray with equally many 0s and 1s. Which approach is correct and linear?
- For an array of 10^5 integers you must count index pairs with a[i] XOR a[j] equal to a fixed K. Which method is the best fit?