• Sign Up
    Time to claim your honor
  • Training
  • Practice
    Complete challenging Kata to earn honor and ranks. Re-train to hone technique
  • Freestyle Sparring
    Take turns remixing and refactoring others code through Kumite
  • Community
  • Leaderboards
    Achieve honor and move up the global leaderboards
  • Chat
    Join our Discord server and chat with your fellow code warriors
  • Discussions
    View our Github Discussions board to discuss general Codewars topics
  • About
  • Docs
    Learn about all of the different aspects of Codewars
  • Blog
    Read the latest news from Codewars and the community
  • Log In
  • Sign Up
phaseon1224 Avatar
Name:Unknown
Clan:Unknown
Member Since:Apr 2019
Last Seen:Oct 2023
Profiles:
Following:0
Followers:0
Allies:0
View Profile Badges
  • Stats
  • Kata
  • Collections
  • Kumite
  • Social
  • Discourse
  • Conversations (9)
  • Replies
  • Authored
  • Needs Resolution
  • Custom User Avatar
    • o2001
    • commented on "The highest profit wins!" python solution
    • 2 years ago

    I'm not too sure, but I think these builtins are internally written in C, making them automatically blazing fast. Calling the solution "horribly inefficient" is really dramatic. On the grand scheme of things, this is still an O(n) solution. It is also incredibly readable. I have run some cursory benchmarks and the "inefficient" method gobsmacks yours for all list lengths I've tried (we're talking around more than 3x faster than yours). Take this with a grain of salt since they're informal tests, but it should hopefully make you reconsider making hasty performance comments in the future. I'll attach it spoilered below.

  • Custom User Avatar
    • akar-0
    • commented on "The highest profit wins!" python solution
    • 2 years ago

    No. If you parse the array twice it's still O(N) (O(2N) == O(N)). O(N^2) would be the case of a nested loop.

  • Custom User Avatar
    • phaseon1224
    • commented on "The highest profit wins!" python solution
    • 2 years ago

    Your reply is non-sensical...I'm not sure where language comes into play here.

    This solution runs in O(N^2) because it requires iterating through the array twice before returning.

    With a two pointer solution, you traverse the array once, in O(N), which is more efficient.

  • Custom User Avatar
    • MircoT
    • commented on "The highest profit wins!" python solution
    • 2 years ago

    if you want efficiency, you should use other programming languages...

    Python is not famous for its efficiency...

  • Custom User Avatar
    • phaseon1224
    • commented on "The highest profit wins!" python solution
    • 2 years ago

    This solution is terribly inefficient.

  • Custom User Avatar
    • ginestah
    • commented on "The highest profit wins!" python solution
    • 2 years ago

    you absolutely should do this in an interview, it shows understanding of the language methods. But come on, nobody is going to ask this in an interview anyway.

  • Custom User Avatar
    • tmills9208
    • commented on "The highest profit wins!" python solution
    • 2 years ago

    unless its coding in python...? please state why. This is more understandable for other, especially more lower-level / typed languages... but why?

  • Custom User Avatar
    • phaseon1224
    • commented on "The highest profit wins!" python solution
    • 2 years ago

    Don't do this during an interview.

  • Custom User Avatar
    • phaseon1224
    • commented on "Reduce My Fraction" python solution
    • 2 years ago

    Don't do this in an interview

  • © 2025 Codewars
  • About
  • API
  • Blog
  • Privacy
  • Terms
  • Code of Conduct
  • Contact

Confirm

  • Cancel
  • Confirm

Collect: undefined

Loading collection data...