# DSA Swift

## How to search an element in Sorted Integer matrix ?

Question : Given an m*n 2D sorted matrix of integers, write a program to find if the given integer exists in the matrix.The matrix has the properties below: Approach #1 By removing row and col in each comparisons . Starting from the top right of matrix, move towards the bottom left in search of the […]

## Find missing number from first N natural numbers.

Question: Find the missing number in first n Natural numbers…

## How to find union of two sorted array ?

[Question]: In a given two sorted array find union elements. Output should be sorted. For example : arr1[] = {1,2,3,4,5} arr2[] = {2,3,4,4,5} Output: {1,2,3,4,5}Approach #1: Use Dictionary / Hashset & after it sort the array which SC: O(m+n) TC: O( (m+n)log(m+n) ) Approach #2: Two pointer approach: use two pointer i & j & fill the

## How to reverse String in swift?

[Question]: Reverse a string with O(1) extra memory. The input string is given as an array of characters like [“C”, “A”, “R”] So here we have used one for loop which iterates half of array & swapping last with first

## Set Matrix Zeroes in swift

Question: – if on given matrix any element is zero set entire row & column to zero [Link] Approach #2  Here we find the rows & cols which is zero & then iterate over matrix & make that rows and cols as zero