Skip to content

Latest commit

 

History

History
75 lines (54 loc) · 1.65 KB

File metadata and controls

75 lines (54 loc) · 1.65 KB

Exercises

1. Find the largest integer in a Stack of Ints

func largestElement <T>(in stack: Stack <T>) -> T? {
  return nil
}



2. Find the sum of a Stack of Ints

func sum(of stack: Stack<Int>) -> Int {
    return 0
}



3. Write a function that pushes a new element to the bottom of a Stack

func pushBottom<T>(stack: Stack<T>, newElement: T) -> Stack<T> {
    return Stack<T>()
}



Valid Braces

4. Write a function that takes a string of braces, and determines if the order of the braces is valid.
It should return true if the string is valid, and false if it's invalid.

This Kata is similar to the Valid Parentheses Kata, but introduces new characters: brackets [],
and curly braces {}. Thanks to @arnedag for the idea!

All input strings will be nonempty, and will only consist of parentheses, brackets
and curly braces: ()[]{}.

What is considered Valid?
A string of braces is considered valid if all braces are matched with the correct brace.

Examples
"(){}[]"   =>  True
"([{}])"   =>  True
"(}"       =>  False
"[(])"     =>  False
"[({})](]" =>  False



Palindrome

5. Solve using two stacks.
Given a string, determine if it is a palindrome, considering only alphanumeric characters
and ignoring cases.

Note: For the purpose of this problem, we define empty string as valid palindrome.

Example 1:

Input: "A man, a plan, a canal: Panama"
Output: true
Example 2:

Input: "race a car"
Output: false