# Sprint 1 Challenge Problems
## [Shortest Distance To a Character](https://leetcode.com/problems/shortest-distance-to-a-character/)
```
class Solution:
"""
Plan
Keep track of the occurences of the character and use two pointers to determine whether which index is closer from the right or left
Runtime: O(length of s)
Space: O(length of s)
"""
def shortestToChar(self, s: str, c: str) -> List[int]:
indices = []
res = []
for i, char in enumerate(s):
if char == c:
indices.append(i)
pointerA = 0
pointerB = min(len(indices) - 1, 1)
for i, char in enumerate(s):
distFromA = abs(i - indices[pointerA])
distFromB = abs(i - indices[pointerB])
res.append(min(distFromA, distFromB))
if distFromB < distFromA:
pointerA = pointerB if pointerB + 1 == len(indices) else pointerB + 1
else:
pointerB = pointerA if pointerA + 1 == len(indices) else pointerA + 1
return res
```
## [Num Lines to Write String](https://leetcode.com/problems/number-of-lines-to-write-string/)
```
class Solution:
"""
Plan
Just manually count the number of lines needed and the width of the current line
Runtime: O(length of s)
Space: O(1)
"""
def numberOfLines(self, widths: List[int], s: str) -> List[int]:
numLines = 1
currLineCharCount = 0
for char in s:
charWidth = widths[ord(char) - ord('a')]
if currLineCharCount + charWidth > 100:
numLines += 1
currLineCharCount = charWidth
else:
currLineCharCount += charWidth
return [numLines, currLineCharCount]
```
## [Are Two String Arrays Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/)
```
"""
Plan
Concatenate all strings from both words and just use the == operator
Runtime (n + m)
Space O(n + m) where n = length of word1, m = length of word2
"""
class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
return "".join(word1) == "".join(word2)
```