<commit_before># Swift Code Challenges
##### programming exercises in Swift.
This is a set of programming exercises/Interview questions implemented in Swift 3.0.

Don't forget to **star** or **watch** the repository; Its content will be expanded and updated frequently.

## Motivation

When I was preparing for technical interviews I noticed an unfortunate lack of resources in Swift.
While in the other hand it was fairly easy to find examples or resources in almost any other programming language. It's gotten way better though now sites like interviewCake have Swift solutions but I feel there is still a lot to do. So I decided to share my solutions so hopefully I can help other people out there.

## Setup / Usage

Just download the **Swift Playgrounds** open them in **Xcode** and uncomment the test function calls to have the code running.

Questions are organized by data structures. There is a playground corresponding to each data structure containing multiple questions.

## The Algorithms.

#### Strings
- Given an array of integers, find the highest product you can get from three of the integers.
- Write a function that counts the number of words in a camelCase string.
- Write a function that checks if a string is a palindrome.
- Write a method to replace all spaces in a string with ‘%20’.

#### Binary Search Tree
Insertion
- Recursion
- No recursion

Search operation
- Recursion
- No recursion

Depth First Traversal
- In-Order
- Pre-Order
- Post-Order

Breadth First Traversal
- Level Order Traversal

Questions
- Given a sorted array, create a binary search tree with minimal height

- Determine if a binary tree is balanced



## Contributors

**These are my solutions and result of my own experimentation and learning process**. If you have better, different or more Swifty like solutions you would like to share **open an issue** and please open a **pull request**.

## License

All content is licensed under the terms of the MIT open source license.<commit_msg>Updated questions in the README<commit_after># Swift Code Challenges
##### programming exercises in Swift.
This is a set of programming exercises/Interview questions implemented in Swift 3.0.

Don't forget to **star** or **watch** the repository; Its content will be expanded and updated frequently.

## Motivation

When I was preparing for technical interviews I noticed an unfortunate lack of resources in Swift.
While in the other hand it was fairly easy to find examples or resources in almost any other programming language. It's gotten way better though now sites like interviewCake have Swift solutions but I feel there is still a lot to do. So I decided to share my solutions so hopefully I can help other people out there.

## Setup / Usage

Just download the **Swift Playgrounds** open them in **Xcode** and uncomment the test function calls to have the code running.

Questions are organized by data structures. There is a playground corresponding to each data structure containing multiple questions.

## The Algorithms.

#### Strings
- Given an array of integers, find the highest product you can get from three of the integers.
- Write a function that counts the number of words in a camelCase string.
- Write a function that checks if a string is a palindrome.
- Write a method to replace all spaces in a string with ‘%20’.
- Write a function that counts the number of words in a camelCase string.
- Write an efficient function that tells us whether or not an input string's openers and closers are properly nested.
- Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?
- Implement a method to perform a basic string compression using the counts of repeated characters. For example, the string aabccccaaa would become a2b1c4a3. If the compressed string would not become smaller than the original string, your method should return the original string.

#### Arrays
- Given a sorted array in which all elementes appear twice(one after one) and one element appears only once. Find that element in O(log n) complexity.
- A magic index in an array A[0…n-1] is defined to be an index such that A[i] = i. Given a sorted array of distinct integers, write a method to find a magic index if one exists, in an array A. FOLLOW UP: What if the values are not distinct?
- Given an array of numbers, split the array into two where one array contains the sum of n-1 numbers and the other array with all the n-1 elements.
- Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0.


#### Stacks

- Write an efficient function that tells us whether or not an input string's openers and closers are properly nested.


#### Binary Search Tree
Insertion
- Recursion
- No recursion

Search operation
- Recursion
- No recursion

Depth First Traversal
- In-Order
- Pre-Order
- Post-Order

Breadth First Traversal
- Level Order Traversal

Questions
- Given a sorted array, create a binary search tree with minimal height

- Determine if a binary tree is balanced

#### Design Patterns.
Quick Overview
-Singleton questions
-Decorator question


## Contributors

**These are my solutions and result of my own experimentation and learning process**. If you have better, different or more Swifty like solutions you would like to share **open an issue** and please open a **pull request**.

## License

All content is licensed under the terms of the MIT open source license.
{'fraction_non_alphanumeric': 0.04843721440321696, 'fraction_numerical': 0.003290074940595869, 'mean_word_length': 4.142857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2158888', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1281, 'n_words': 857}