Company: THOUGHT WORKS_10thjuly

Difficulty: medium

Problem Statement

Problem Statement A farmer planted crops in a field and observed variations in plant heights. To assess the overall growth, he devised a formula. Given a row of plants represented by an array crop , where each element crop[i] denotes the height of the plant at position i , determine whether the crop is growing well. The crop is said to be growing well if there exist two different positions i and j ( i ≠ j ) that satisfy both of the following conditions: |i - j| ≤ position — the two plants are at most position indices apart. |crop[i] - crop[j]| ≤ height — their heights differ by at most height . Note: A negative value in crop[i] indicates undergrowth; it is still a valid height and is compared normally. If position or height is negative, or if there are fewer than 2 plants, no valid pair can exist. Input Format The first line contains an integer position . The second line contains an integer height . The third line contains an integer n , the number of plants. Each

More THOUGHT WORKS_10thjuly OA questionsInterview experiences