bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 2100. Find Good Days to Rob the Bank

2100. Find Good Days to Rob the Bank

Leetcode Solutions

Prefix and Suffix Array Approach

  1. Initialize two arrays, left and right, of the same length as the security array, to store the lengths of the non-increasing and non-decreasing sequences, respectively.
  2. Fill the left array by iterating from left to right. For each index i, if security[i] is less than or equal to security[i-1], increment the count from the previous index; otherwise, reset the count to 1.
  3. Fill the right array by iterating from right to left. For each index i, if security[i] is less than or equal to security[i+1], increment the count from the next index; otherwise, reset the count to 1.
  4. Iterate through the security array and check for each day i if left[i] and right[i] are both greater than time. If so, add the day i to the list of good days.
  5. Return the list of good days.
UML Thumbnail

Brute Force with Caching

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...