Giter Club home page Giter Club logo

algorithmic-toolbox's People

Contributors

mablatnik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

algorithmic-toolbox's Issues

question with regards to week1/max_pairwise_product.py

Hi,

With regards to week1/max_pairwise_product.py
would you please explain what does "if max_index1 == -1" do in the if condition in the for loop?

since max_index1 is initially assigned to -1, why do we need that in the if loop again? I did test it and knew that the answer wouldn't be right without that condition, but I can't figure out why.
Thanks!

**Just add this code, the previous code exceeds the time**

    **Just add this code, the previous code exceeds the time**

#include
#include
#include

using std::cin;
using std::cout;
using std::vector;

long long MaxPairwiseProduct(const vector &numbers)
{
long long result = 0;
int n = numbers.size();
for (int i = 0; i < n; ++i)
{
for (int j = i + 1; j < n; ++j)
{
if (((long long)(numbers[i])) * numbers[j] > result)
{
result = ((long long)(numbers[i])) * numbers[j];
}
}
}
return result;
}

long long MaxPairwiseProductFast(const vector &numbers)
{
int n = numbers.size();

int max_index1 = -1;
for (int i = 0; i < n; ++i)
    if ((max_index1 == -1) || (numbers[i] > numbers[max_index1]))
        max_index1 = i;

int max_index2 = -1;
for (int j = 0; j < n; ++j)
    if ((j != max_index1) && ((max_index2 == -1) || (numbers[j] > numbers[max_index2])))
        max_index2 = j;

return ((long long)(numbers[max_index1])) * numbers[max_index2];

}

int main()
{
int n;
cin >> n;
vector numbers(n);
for (int i = 0; i < n; ++i)
{
cin >> numbers[i];
}

long long result = MaxPairwiseProductFast(numbers);
cout << result << "\n";
return 0;

}

Originally posted by @maayaankk in #6 (comment)

Completely Wrong answer!

Your week 3 largest number is nowhere even closer to the actual solution, so many syntax and semantic mistakes are there. I suggest correct it.

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.