Skip to content

BoykoMihail/SwiftAlgorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftAlgorithms

Overview

Welcome to SwiftAlgorithms! This repository contains a collection of algorithms implemented in Swift.

Algorithms

Easy

  1. Two Sum
    • Description: Find two numbers in an array that sum up to a specific target.
    • Implementation: Two Sum
  2. Palindrome Number
    • Description: Given an integer x, return true if x is a palindrome, and false otherwise.
    • Implementation: Palindrome Number
  3. 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
  4. 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
  5. Majority Element
    • Description: Given an array nums of size n, return the majority element.
    • Implementation: Majority Element
  6. Best Time to Buy and Sell Stock

Medium

  1. Add Two Numbers (Linked Lists)
    • Description: Add two numbers represented by linked lists.
    • Implementation: Add Two Numbers
  2. Longest Substring Without Repeating Characters
  3. Longest Palindromic Substrings
  4. 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
  5. Reverse Integer
    • Description: Given a signed 32-bit integer x, return x with its digits reversed.
    • Implementation: Reverse Integer
  6. 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)
  7. 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
  8. 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
  9. Best Time to Buy and Sell Stock II
  10. 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
  1. Jump Game2
  • 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
  1. H-Index
  • 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

Hard

  1. Median of Two Sorted Arrays
  2. Regular Expression Matching

Concurrency

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. Concurrent Map Reduce
    • Description: Implement a concurrent map-reduce algorithm to process a large dataset in parallel.
    • Implementation: Concurrent Map Reduce
  8. Bounded Buffer with Multiple Producers and Consumers
  9. 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
  10. Concurrent Access to Shared Resource

Contribution

Contributions are welcome! Feel free to submit a pull request with your algorithm implementations or improvements.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages