Question bank › Dynamic Programming
Dsa Dynamic Programming Warm-up

Garden Path Plants

You are designing a garden and you want to plant flowers in a straight path. Each position in the garden can hold only one flower. You have 'n' positions (numbered from 0 to n-1) and a list of flower types available to plant. The objective is to maximize the number of flowers planted, where adjacent flowers cannot be of the same type. Write a function that takes the number of positions 'n' and a list of flower types, and returns the maximum number of flowers that can be planted. Input Format: - The first line contains an integer n (1 <= n <= 100). - The second line contains space-separated distinct integers representing the flower types (1 <= type <= 1000). Output Format: - A single integer representing the maximum number of flowers that can be planted. Example: Input: 5 1 2 3 Output: 5 Note: You can plant a different flower in all positions.

Key concepts

dynamic_programmingrecursionmemoization

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.