As of May 31, 2023, we have updated our Code of Conduct.

New answers tagged

1 vote
Accepted

Python Logic Gate Circuit Simulator

Note: In the future, you should probably post a snippet of your code that you have the most doubts about or that is typical of your code, then provide a link to the rest. All good though! Overall, ...
Fuzzy Muffin's user avatar
1 vote

Efficient Solution for Finding Product of Largest Pair in Array

If you sort the input, then the larger the item, the bigger the index of the item will be. So the largest two items would simply be the last two items. And you can simply access them by using indexing:...
Ξένη Γήινος's user avatar
1 vote

Efficient Solution for Finding Product of Largest Pair in Array

You can almost halve the number of comparisons to expect for large uniform random input comparing to the runner-up first: ...
greybeard's user avatar
  • 5,499
1 vote

Efficient Solution for Finding Product of Largest Pair in Array

You can simplify your code by using heapq.nlargest. Since heapq is written in C, with a Python fallback, the code is likely faster than pure Python. The docs say ...
Peilonrayz's user avatar
  • 42.3k
2 votes
Accepted

Determine the chance a streak of 6 HEADs or 6 TAILS appear in 100 flips, repeated 10000 times

Logical numberOfStreaks += (int(len(item)) // 6) Does a streak of 12 H mean 2 streaks? how often a streak of six ...
Kache's user avatar
  • 336

Top 50 recent answers are included