# Array-Strings

Array DSA problems in swift.

## How to Remove all occurrence of certain number ?

[Question]: Given an integer array nums and an integer k, remove all occurrences of k in nums in-place. The order of the elements may be changed. Then return the count after removal Approach: We can declare a variable which holds index initial it’s 0 now move elements which are not matched with k

## How to find longest Substring Without Repeating Characters ?

[Question]: Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = “abcabxy” Output: 5 Explanation: The answer is “abcxy”, with the length of 5

## Subarray Sum Equals K

[Question]: In an array nums and an integer k, return the total number of subarrays whose sum equals to k. Example 1: Input: nums = [1,1,1], k = 2 Output: 2 Example 2: Input: nums = [1,2,3], k = 3 Output: 2

## How to find Maximum Product Subarray?

[Question]: Given an integer array nums, find a subarray that has the largest product, and return the product. The test cases are generated so that the answer will fit in a 32-bit integer. Example 1: Input: nums = [2,3,-2,4] Output: 6 Explanation: [2,3] has the largest product 6. Example 2: Input: nums = [-2,0,-1] Output: 0 Explanation: The result cannot be …

## Count inversions in an array

[Question]: Given an array of N integers, count the inversion of the array (using merge-sort). What is an inversion of an array? Definition: for all i & j < size of array, if i < j then you have to find pair (A[i],A[j]) such that A[j] < A[i].Example 1:Input Format: N = 5, array[] = {1,2,3,4,5}Result: …

## Find the repeating and missing numbers

[Question]:Given an unsorted array of size n. Array elements are in the range of 1 to n. One number from set {1, 2, …n} is missing and one number occurs twice in the array. Find these two numbers.Input: arr[] = {3, 1, 3}Output: Missing = 2, Repeating = 3Explanation: In the array, 2 is missing and 3 occurs …

## Merge two Sorted Arrays Without Extra Space

[Question]: Given two sorted arrays arr1[] and arr2[] ofsizes n and m in non-decreasing order. Merge them in sorted order without using any extra space. Modify arr1 so that it contains the first N elements and modify arr2 so that it contains the last M elements. Example 1: Input: n = 4, arr1[] = [1 3 5 7] m = 5, arr2[] = …

## Merge all overlapping intervals

[Question]: Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.Example: – Input: intervals = [[1,3],[2,6],[8,10],[15,18]] Output: [[1,6],[8,10],[15,18]] Explanation: Since intervals [1,3] and [2,6] overlap, merge them into [1,6]. Constraints: 1 <= intervals.length <= 104 intervals[i].length == 2 0 <= …

## Count the number of subarrays with given xor K

[Question]: Problem Statement: Given an array of integers A and an integer B. Find the total number of subarrays having bitwise XOR of all elements equal to k.Example 1:Input Format: A = [4, 2, 2, 6, 4] , k = 6Result: 4Explanation: The subarrays having XOR of their elements as 6 are [4, 2], [4, 2, …

## Length of the longest subarray with zero Sum

[Question]: Problem Statement: Given an array containing both positive and negative integers, we have to find the length of the longest subarray with the sum of all elements equal to zero.Input array = [9, -3, 3, -1, 6, -5]Result: 5Explanation: The following subarrays sum to zero:{-3, 3} , {-1, 6, -5}, {-3, 3, -1, 6, -5}Since …