# Array-Strings

Array DSA problems in swift.

## 4 Sum | Find Quads that add up to a target value4 Sum

[Question]: Find Quads that add up to a target value4 Sum Approach# using the 4 pointers Two pointers a & b are fixed and we have two moving pointers c and d. where c starts from b + 1 and d is start from last index Complexity Analysis Time Complexity: O(N3), where N = size of …

## 3 Sum : Find triplets that add up to a zero

[Question]: Find triplets that add up to a zero (3 sum) Input: nums = [-1,0,1,2,-1,-4] Output: [[-1,-1,2],[-1,0,1]] Explanation: nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0. nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0. nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) …

## Find all elements that appear more than ⌊ n/3 ⌋ times.

[Question]: Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.Example: Input =  [11, 33, 33, 11, 33, 11]; Output:–// [11,33] Approach: By using dictionary

## Find next lexicographically greater permutation

[Question]: A permutation of an array of integers is an arrangement of its members into a sequence or linear order.For example, for array = [1,2,3], the following are all the permutations of array: [1,2,3], [1,3,2], [2, 1, 3], [2, 3, 1], [3,1,2], [3,2,1]

## Get Spiral Traversal of Matrix

[Question]:  Given a Matrix, print the given matrix in spiral order.Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,2,3,6,9,8,7,4,5]

## Rotate array matrix by 90 degree

[Question] : Given a 2D matrix, your task is to rotate the matrix 90 degrees clockwise.Input: –  [[1, 2, 3], [4, 5, 6], [7, 8, 9]]Output –  [[7, 4, 1], [8, 5, 2], [9, 6, 3]]

## Find Longest consecutive sequence

[Question]: Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time.Example: I/P = [200,4,2,1,3,100].. Output-> 4 because 1,2,3,4 is largest consecutive. Now a similar problem which gives consecutive array