Memory Reader
Practice
3.6 (13 votes)
Dynamic programming
Algorithms
Introduction to dynamic programming 1
Problem
46% Success 2008 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

There is a new AI in town. It reads through horizontal strips of memory. Let the strip of memory be divided into blocks numbered \(1,2,3...\) etc. There is good data at some integer points on the memory given in an array \(memory\). The AI can only read at these points. The AI aims to read the last point of good memory. Also, the AI can only move in the forward direction.

To read a memory, it can move from one good point to another. It can move its reader pointer to either \(L-1\) or \(L\) or \(L+1\) points if the length of its last jump was \(L\). Initially, it is at point 0 (which is always a good memory). The first move can only be to the first good memory point. Determine if it can move to the last memory. It is ensured that the good memory points are given in sorted order.

Note: The AI doesn’t need to read all the good memory points.

Input format:

  • The first line contains \(T\), denoting the number of test cases.

  • The first line of each test case contains one integer \(N\), denoting the number of good memory points.

  • The second line of each test case contains an array \(memory\) of \(N\) space-separated integers, denoting the position of the good memory points.

Output format:

For each test case, print the string \(YES\) if the AI can read the last memory point, else print the string \(NO\).

Constraints:

\(1 <= T <= 10\)
\(1 <= N <= 10^3 \)

\(1 <= memory[i] <= 10^9\)

\(memory[i] < memory[i+1]\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
15 votes
Tags:
AlgorithmsDynamic ProgrammingHiringMedium
Points:30
24 votes
Tags:
ApprovedMathMediumOpen
Points:30
9 votes
Tags:
AlgorithmsDynamic Programming