Coder Social home page Coder Social logo

algorithms's Introduction

Algorithms Playground for Andrea ❤️

Installation

source env/bin/activate

Usage

For max product cassidoo_newsletter/2024/05:

  • Description: Write a function that takes in a list (of length >= 3) of numbers, and returns the maximum product that can be obtained by multiplying any three integers from the list

  • Example:

maxProduct([2, 4, 1, 3, -5, 6])
72 (4*3*6)

Solution:

cd cassidoo_newsletter/2024/05
python max_product 1 2 3 5 6 3

Author's notes

The approach to this problem depends on the situation. To make this interesting, let's think in a large list and a variable number of integers that need to be multiplied:

  • Sorted list gives time complexity of O(1), only the three first numbers and the two last need to be accessed. But what if this list changes frequently, every write to the sorted list is O(n)
  • Heap gives time complexity of O(n), as there are a number of mins to find, each search requires a new heapify process.

For sort by number of vowels cassidoo_newsletter/2024/06:

  • Description: Write a function that takes a list of names and returns the names sorted by the number of vowels in each name in descending order. If two names have the same number of vowels, sort them alphabetically.

  • Example:

example_list = ["Goku", "Vegeta", "Piccolo", "Gohan"]
sorted_list = sort_vowels(example_list)
expected_sorted_list =  ["Piccolo", "Vegeta", "Gohan", "Goku"]
assert expected_sorted_list == sorted_list 

Solution:

cd cassidoo_newsletter/2024/06
python sort_vowels_number.py Andrea Oscar Emilia Cassidy

Returns:

['Emilia', 'Andrea', 'Cassidy', 'Oscar']

License

MIT

algorithms's People

Contributors

mamontesp avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.