Knowee
Questions
Features
Study Tools

An avid hiker keeps meticulous records of their hikes. During the last hike that took exactly steps, for every step it was noted if it was an uphill, , or a downhill, step. Hikes always start and end at sea level, and each step up or down represents a unit change in altitude. We define the following terms:A mountain is a sequence of consecutive steps above sea level, starting with a step up from sea level and ending with a step down to sea level.A valley is a sequence of consecutive steps below sea level, starting with a step down from sea level and ending with a step up to sea level.Given the sequence of up and down steps during a hike, find and print the number of valleys walked through.Example The hiker first enters a valley units deep. Then they climb out and up onto a mountain units high. Finally, the hiker returns to sea level and ends the hike.Function DescriptionComplete the countingValleys function in the editor below.countingValleys has the following parameter(s):int steps: the number of steps on the hikestring path: a string describing the pathReturnsint: the number of valleys traversedInput FormatThe first line contains an integer , the number of steps in the hike.The second line contains a single string , of characters that describe the path.ConstraintsSample Input8UDDDUDUUSample Output1ExplanationIf we represent _ as sea level, a step up as /, and a step down as \, the hike can be drawn as:_/\ _ \ / \/\/The hiker enters and leaves one valley.

Question

An avid hiker keeps meticulous records of their hikes. During the last hike that took exactly steps, for every step it was noted if it was an uphill, , or a downhill, step. Hikes always start and end at sea level, and each step up or down represents a unit change in altitude. We define the following terms:A mountain is a sequence of consecutive steps above sea level, starting with a step up from sea level and ending with a step down to sea level.A valley is a sequence of consecutive steps below sea level, starting with a step down from sea level and ending with a step up to sea level.Given the sequence of up and down steps during a hike, find and print the number of valleys walked through.Example The hiker first enters a valley units deep. Then they climb out and up onto a mountain units high. Finally, the hiker returns to sea level and ends the hike.Function DescriptionComplete the countingValleys function in the editor below.countingValleys has the following parameter(s):int steps: the number of steps on the hikestring path: a string describing the pathReturnsint: the number of valleys traversedInput FormatThe first line contains an integer , the number of steps in the hike.The second line contains a single string , of characters that describe the path.ConstraintsSample Input8UDDDUDUUSample Output1ExplanationIf we represent _ as sea level, a step up as /, and a step down as , the hike can be drawn as:_/\ _ \ / //The hiker enters and leaves one valley.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The problem is asking to find the number of valleys the hiker has walked through. A valley is defined as a sequence of consecutive steps below sea level, starting with

Similar Questions

Which integer represents this situation?  You hike 100 feet down a mountain.*1 point100 ft.10 ft.-100 ft.-10 ft.

Dan ended a hike at an elevation of 951 metres above sea level. He had started at an elevation of 178 metres above sea level. What was Dan's change in elevation?Write your answer as an integer (for example, -3).

RECONGNIZING FORMS OF CONICAL HILLS ,PLATEAUS ,ESCARPMENT AND CLIFF

Graph the hikers' progress.The first point on the line coincides with the _________ rate:the rate of increase in elevation of _______ feet per hour.The graph starts at the _____________, because the hikersstarted at base camp.The last point on the line indicates the total elevation increasefor the duration of the hike.

Choose the adjective in the sentence: "We hiked to the top of the steep mountain."

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.