Search
⌘K

Leetcode 2420. Find All Good Indices

Find indices i (k <= i < n-k) such that the k elements before i form a non-increasing sequence and the k elements after i form a non-decreasing sequence. Precompute lengths of non-increasing suffixes and non-decreasing prefixes (or equivalent) to test each candidate in O(1), yielding an overall O(n) time and O(n) space solution.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.