Skip to content

Instantly share code, notes, and snippets.

View avii-7's full-sized avatar
🚣
On a raft.

A V I I avii-7

🚣
On a raft.
View GitHub Profile
@avii-7
avii-7 / COW.md
Last active July 14, 2024 17:41
Swift Learnings

Swift — “copy-on-write”

"copy on write" is an optimization technique that helps in managing memory more efficiently.

It is used primarly with value types such as Array, Dictionary and String to defer the actual copying of data until it is modified. This helps in minimizing unnecessary data copying and thus improve performance.

How "copy on write" works ?

When you assign or pass a value type to another variable or function. Swift doesn't immediately creates the copy of data. Instead it shares the same underlying storage until the copy is modified.

@avii-7
avii-7 / A20.swift
Last active July 14, 2024 03:42
Array - DSA Questions
// Two Sum : Check if a pair with given sum exists in Array ( 1. Two Sum )
// Problem Link: https://leetcode.com/problems/two-sum/description/
// Article Link: https://takeuforward.org/data-structure/two-sum-check-if-a-pair-with-given-sum-exists-in-array/
// Brute Force Approch
// O(n * n)
// TC -> O(1)
// ThoughtProcess
@avii-7
avii-7 / BuildError.txt
Created July 11, 2024 07:40
Error - M1 Chip machines.
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/17.2.8053/targets/Xamarin.Shared.Sdk.targets(1560,3): error : clang++ exited with code 1: [/Users/marcusfalck/MeetApp Mobile git repo/Ventla.iOS/Ventla.iOS.csproj]
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/17.2.8053/targets/Xamarin.Shared.Sdk.targets(1560,3): error : Undefined symbols for architecture arm64: [/Users/marcusfalck/MeetApp Mobile git repo/Ventla.iOS/Ventla.iOS.csproj]
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/17.2.8053/targets/Xamarin.Shared.Sdk.targets(1560,3): error : "_SDWebImageCoderScaleDownLargeImagesKey", referenced from: [/Users/marcusfalck/MeetApp Mobile git repo/Ventla.iOS/Ventla.iOS.csproj]
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/17.2.8053/targets/Xamarin.Shared.Sdk.targets(1560,3): error : -exported_symbol[s_list] command line option [/Users/marcusfalck/MeetApp Mobile git repo/Ventla.iOS/Ventla.iOS.csproj]
/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/17.2.8053/targets/Xamarin.Shared.Sdk.targets(1560,3): erro
@avii-7
avii-7 / DispatchGroup.md
Last active July 16, 2024 15:50
Multi-Threading - Swift

Dispatch Group

It is used to manage the execution of multiple tasks concurrently, can be used in a situation where you need to aggregate the results of these tasks before proceeding further.

DispatchGroup is not the best choice when one task is dependent on other.

Initialization:

let group = DispatchGroup()
@avii-7
avii-7 / A11.java
Last active June 4, 2024 15:49
Union of Two Sorted Arrays
// Problem Link: https://www.geeksforgeeks.org/problems/union-of-two-sorted-arrays-1587115621/1
// Brute Force Approch
// TC -> O(nlogk) + O(mlogk) + O(n+m)
// where k is size of set.
// SC -> O(n+m) + O(n + m)
// 1. O(n+m) -> For solve the problem
// 2. O(n+m) -> For return the answer.
@avii-7
avii-7 / A19.java
Last active June 9, 2024 19:26
Longest Subarray with given Sum K ( Positives and Positives + Negatives )
// Problem Link: ( GFG ) https://www.geeksforgeeks.org/problems/longest-sub-array-with-sum-k0809/1
// Striver: https://takeuforward.org/data-structure/longest-subarray-with-given-sum-k/
//Brute Force Approch
// TC -> O(n*n)
// SC -> O(1)
// ThoughtProcess
// 1. We will generate all the subarrays.
// 2. And then check if sum if equal to K.
@avii-7
avii-7 / A18.swift
Last active June 9, 2024 13:06
Find the number that appears once, and the other numbers twice (LC: 136. Single Number )
// Problem Link: https://leetcode.com/problems/single-number/description/
// Brute force approch
// TC -> O(n*n) ( nearby )
// SC -> O(1)
// Thought Process:
// 1. Take one element from array and check for it's duplicates using another loop.
// 2. If it's exists do nothing, it not return that element.
@avii-7
avii-7 / A17.swift
Last active June 28, 2024 17:55
Find the missing number in the array >> A17.swift
// Problem Link: https://leetcode.com/problems/missing-number/
//Brute force approch
// TC -> O(n*n)
// SC -> O(1)
// ThoughtProces
// 1. Check every number from range [0...n] in array.
// 2. if it is not exist return that number.
@avii-7
avii-7 / A15.java
Last active June 29, 2024 09:19
Merge 2 Sorted Array | A15.java
// Problem Link: https://www.naukri.com/code360/problems/sorted-array_6613259
// Brute Force Approch
// Thought Process
// First, I'm collecting both the array elements into one new array which costs me O(n+m) time complexity and O(n+m)
// space complexity.
// Next, I'm sorting the array in-place which cost me arround O(klogk) where k = n+m
// Next, I'm removing any duplicates from sorted array, cost O(n+m) time complexity.
@avii-7
avii-7 / A16.swift
Last active June 29, 2024 17:21
Move all Zeros to the end of the array | A16.swift
int[] arr = [1, 2, 0, 0, 2, 3];
//Brute Force Approch
1. Save all non-zero elements into temp array.
2. Fill non-zero elements from temp into the first of the given array.
3. Fill zero's to the remaining.
TC -> O(n + x + n - x) => O(2n)
SC -> O(n) ( Worst case )