Member-only story
LeetCode Weekly Contest 195 Swift Solutions
Array subsequences feature!
This article is about the 4 challenges in the LeetCode Weekly Contest 195. That is
- 1496 Path Crossing
- 1497 Check If Array Pairs Are Divisible by k
- 1498 Number of Subsequences That Satisfy the Given Sum Condition
- 1499 Max Value of Equation
The solutions assume some knowledge of Big O notation
The Problems
Each problem will be approached in turn, with a solution and also with articles explaining the tools, techniques and theory that will help you solve these problems yourself.
Let us get started!
1496. Path Crossing
I have used some knowledge of Strings and Characters in Swift to make this solution a little faster.
Given a String
of paths represented as the single characters ‘N, ‘S’, ‘E’ and ‘W’ a path is formed from the origin (0,0) where ‘N, ‘S’, ‘E’ and ‘W’ represent moving up, down, east and west respectively.
I decided to represent each location as a pair (and since there will be comparisons this will need to conform to Hashable resulting in
struct Pair: Hashable {
var…