Welcome to SwiftAlgorithms! This repository contains a collection of algorithms implemented in Swift.
- Two Sum
- Description: Find two numbers in an array that sum up to a specific target.
- Implementation: Two Sum
- Palindrome Number
- Description: Given an integer x, return true if x is a palindrome, and false otherwise.
- Implementation: Palindrome Number
- Smallest Index With Equal Value
- Description: Given a 0-indexed integer array nums, return the smallest index i of nums such that i mod 10 == nums[i], or -1 if such index does not exist.
- Implementation: Smallest Index With Equal Value
- Remove Duplicates from Sorted Array
- Description: Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once.
- Implementation: Remove Duplicates from Sorted Array
- Majority Element
- Description: Given an array nums of size n, return the majority element.
- Implementation: Majority Element
- Best Time to Buy and Sell Stock
- Description: You are given an array prices where prices[i] is the price of a given stock on the ith day.
- Implementation: Best Time to Buy and Sell Stock
- Add Two Numbers (Linked Lists)
- Description: Add two numbers represented by linked lists.
- Implementation: Add Two Numbers
- Longest Substring Without Repeating Characters
- Description: Find the length of the longest substring without repeating characters.
- Implementation: Longest Substring Without Repeating Characters
- Longest Palindromic Substrings
- Description: Return the longest palindromic substring in sring.
- Implementation: Longest Palindromic Substrin
- Zigzag Conversion
- Description: The string is written in a zigzag pattern on a given number of rows. Write the code that will take a string and make this conversion.
- Implementation: Zigzag Conversion
- Reverse Integer
- Description: Given a signed 32-bit integer x, return x with its digits reversed.
- Implementation: Reverse Integer
- String to Integer (atoi)
- Description: Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).
- Implementation: String to Integer (atoi)
- Remove Duplicates from Sorted Array II
- Description: Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place such that each unique element appears at most twice.
- Implementation: Remove Duplicates from Sorted Array II
- Rotate Array
- Description: Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.
- Implementation: Rotate Array
- Best Time to Buy and Sell Stock II
- Description: You are given an integer array prices where prices[i] is the price of a given stock on the ith day.
- Implementation: Best Time to Buy and Sell Stock II
- Jump Game
- Description: You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position. Return true if you can reach the last index, or false otherwise.
- Implementation: Jump Game
- Description: You are given a 0-indexed array of integers nums of length n. You are initially positioned at nums[0]. Return the minimum number of jumps to reach nums[n - 1]. The test cases are generated such that you can reach nums[n - 1].
- Implementation: Jump Game2
- Description: Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return the researcher's h-index.
- Implementation: H-Index
- Median of Two Sorted Arrays
- Description: Find the median of the two sorted arrays.
- Implementation: Median of Two Sorted Arrays
- Regular Expression Matching
- Description: Implement regular expression matching with support for '.' and '*'.
- Implementation: Regular Expression Matching
- Producer-Consumer Problem
- Description: Design a system where one or more producers generate data and place it into a buffer, and one or more consumers take data from the buffer. Ensure that the buffer never overflows and that consumers do not try to consume from an empty buffer.
- Implementation: Producer-Consumer Problem
- Dining Philosophers Problem
- Description: Five philosophers sit around a table with a fork between each pair. They spend their time thinking and eating. However, a philosopher can only eat if they have both forks. Design a synchronization mechanism to avoid deadlock.
- Implementation: Dining Philosophers Problem
- Readers-Writers Problem
- Description: Design a system where multiple threads can read a shared resource, but only one thread can write to it at a time. Ensure that readers do not starve writers and vice versa.
- Implementation: Readers-Writers Problem
- Barbershop Problem
- Description: In a barbershop with one barber, multiple customers can enter. If the barber is busy, customers wait. If there are no customers, the barber sleeps. Design a synchronization mechanism for this scenario.
- Implementation: Barbershop Problem
- Traffic Light Intersection
- Description: Design a traffic light system for an intersection where traffic lights change to allow vehicles from different directions to pass safely without collisions.
- Implementation: Traffic Light Intersection
- Thread Pool
- Description: Design a thread pool where a fixed number of threads process tasks from a queue. This ensures that the system does not get overwhelmed by too many concurrent tasks.
- Implementation: Thread Pool
- Concurrent Map Reduce
- Description: Implement a concurrent map-reduce algorithm to process a large dataset in parallel.
- Implementation: Concurrent Map Reduce
- Bounded Buffer with Multiple Producers and Consumers
- Description: Extend the Producer-Consumer problem to support multiple producers and consumers with a bounded buffer.
- Implementation: Bounded Buffer with Multiple Producers and Consumers
- Asynchronous File Processing
- Description: Process files asynchronously where multiple threads read from different files, process the content, and write the results to another file.
- Implementation: Asynchronous File Processing
- Concurrent Access to Shared Resource
- Description: Design a system where multiple threads need to safely access and modify a shared resource.
- Implementation: Concurrent Access to Shared Resource
Contributions are welcome! Feel free to submit a pull request with your algorithm implementations or improvements.
This project is licensed under the MIT License - see the LICENSE file for details.