Menu
CoddyTech

Recap: Rising Steps

Lesson 20 of 48 in Coddy's Swift for Java Developers course.

challenge icon

Challenge

Easy

Implement rises(_:): count adjacent pairs where the later value is strictly larger. Input contains 0 through 50 integers -100 through 100. Output the count.

Implement the required APIs and solve(_ input: String) -> String. Return output text without a final newline; do not print in editable code. The locked driver independently checks the APIs on additional valid inputs, then prints the returned text with exactly one newline. All numeric operations stay within Int bounds.

Your code goes in Functions.swift. main.swift holds the supplied input/output code and cannot be edited.

Try it yourself

import Foundation
func apiChecks(_ input: String) -> Bool {
return rises([4,2,3,8]) == 2 && rises([1,1]) == 0 && rises([]) == 0
}
let input = String(data: FileHandle.standardInput.readDataToEndOfFile(), encoding: .utf8)!
// BEGIN PUBLIC API PROBES
let apiOK = apiChecks(input)
// END PUBLIC API PROBES
if apiOK { print(solve(input)) } else { print("API mismatch") }

All lessons in Swift for Java Developers

Practice on your own: Swift playground