Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 300 Longest Increasing Subsequence - Binary Search Walkthrough

O(n log n) algorithm trace

Trace the O(nlogn)O(n \log n) LIS on [10,9,2,5,3,7,101,18][10, 9, 2, 5, 3, 7, 101, 18] using the tails array. tails=[]tails = []. Process 1010: tails=[10]tails = [10]. Process 99: replace 1010 with 99, tails=[9]tails = [9].

Process 22: replace 99, tails=[2]tails = [2]. Process 55: append, tails=[2,5]tails = [2, 5]. Process 33: replace 55, tails=[2,3]tails = [2, 3]. Process 77: append, tails=[2,3,7]tails = [2, 3, 7]. Process 101101: append, tails=[2,3,7,101]tails = [2, 3, 7, 101]. Process 1818: replace 101101, tails=[2,3,7,18]tails = [2, 3, 7, 18]. Length: 44.