Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Uluthando needs your help to plant some trees. He can give you three parameters of the land: - width of the land w - length

Uluthando needs your help to plant some trees. He can give you three parameters of the land:

- width of the land w

- length of the land l

- gap between the trees g

You have to create an algorithm to return the number of trees which can be planted on the edges of the given land in a symmetrical layout shown below (unsymmetrical gap = x, tree = o, gap = -):

w=3, l=3, g=1

plantTrees(w, l, g) 4

o - o

- -

o - o

// Uluthando can plant 4 trees.

w=3, l=3, g=3

plantTrees(w, l, g) 2

o - -

- -

- - o

// Uluthando can plant 2 trees.

If the layout is not symmetrical, you have to return 0:

w=3, l=3, g=2

plantTrees(w, l, g) 0

o - -

x o

x x x

// Planting 2 trees mean the gap of two trees will be greater than 2.

o - -

x o

o - -

// Planting 3 trees mean the gap of two trees will be less than 2.

Another Example for better understanding:

w=3, l=3, g=0

plantTrees(w, l, g) 8

o o o

o o

o o o

// Uluthando can plant 8 trees.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions