## How to print Patterns in swift ?

Below are the example code for various type of patterns in swift language. Reference Link: Take You Forward

Array DSA problems in swift.

Below are the example code for various type of patterns in swift language. Reference Link: Take You Forward

[Question]: In a given array sort all 0s 1s & 2s .For example: I/P {0, 1, 2, 0, 1, 2} o/p:: {0, 0, 1, 1, 2, 2}Solution:- We can use three pointers low, mid & high. Where low & mid is start index(i.e. 0) & high is arrayLength – 1. In a while loop we …

The good approach will be to use log10 Time complexity O(1) Space complexity O(1) . The number of digits in an integer = the upper bound of log10(n).Example: log10(12345.0)) = > 4.091491094267951 so we have to use 4+1

[Question]: Reverse Integer in swift ex. 12345 => 54321 output should lie in Int32 Range Explanation: Here we are multiplying result with10 further adding it to modulo(reminder) & get last element by divide by 10

[Question]: Find maximum sum of a subarray of size k example [9,1,3,2,6,1,5,9], k: 4 = output: 21 (6+1+5+9)Solution: with sliding window we can achieve. first we take sum of first k elements further move elements by 1 window size & add the latest var & remove last var.

[Question]: Given an integer array that may contain duplicates, find all possible subsets (the power set). No duplicates allowed in answer. Solution in any order allowed.

[Question ] Check weather array is palindrome Example : [1,2,2,1] ===> It’s palindrome Solution#: Here we are checking first & last element equality & increase till mid of array

# Question 1: Find sum of first n numbers. Example :– n = 3 => 3+2+1 =6. We will use recursion to solve this problem. # Question 2: Find sum of array elements using recursion approach :

[Question] In a given array return true if array have duplicate elements . For example 1 :[1,2,3,1] = True example 1 :[1,2,3,] = False So here we have used Dictionary which is Hashable which contains only unique keys hence we can find duplicates elements in swift.

[Question] Find Maximum and minimum of an array in swift using minimum number of comparisons #Approach: 1 Use first element as min max & start loop from second element onwards & return tuple of the min max number