Skip to main content

All Questions

Filter by
Sorted by
Tagged with
4 votes
0 answers
169 views

Finding the number of possible paths in a cave system (Python)

I've finally come up with working solution for day 12 of AdventOfCode, where you have to find the number of possible paths in a cave system following a given set of rules (described below). My ...
Oleg Shevchenko's user avatar
3 votes
1 answer
231 views

Killing a Hydra - Overengineered

Background This question is inspired by the question: Killing a hydra, and my response therein. I will restate the problem at hand in full so that this question is fully self contained You can only ...
N3buchadnezzar's user avatar
9 votes
1 answer
947 views

Number in words: recursive function

I would appreciate some feedback on the below code I wrote for a Project Euler problem. The answer comes out correct but I'd like feedback on the design of the function and implementation of ...
engineer.larry's user avatar
9 votes
1 answer
210 views

Tower of Hanoi with helper function

Here is my solution to the Tower of Hanoi problem using Python ...
MrJoe's user avatar
  • 2,143
8 votes
1 answer
2k views

Codewars: N-dimensional Von Neumann Neighborhood in a matrix

Task: For creating this challenge on Codewars I need a very performant function that calculates Von Neumann Neighborhood in a N-dimensional array. This function will be called about 2000 times The ...
Superluminal's user avatar
6 votes
2 answers
2k views

Find the second largest number in an array with at most n + log2 n - 2 comparisons

This exercise is from Roughgarden's (excellent) course on algorithms on Coursera: You are given as input an unsorted array of n distinct numbers, where n is a power of 2. Give an algorithm that ...
ajeje's user avatar
  • 161
2 votes
1 answer
2k views

Given a binary tree, find the maximum path sum

This is a leetcode.com problem. For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must ...
Stack crashed's user avatar
2 votes
3 answers
17k views

Generate all permutations of a list in Python

This is my solution to the "Permutations" problem from Leetcode: Given a collection of distinct numbers, return all possible permutations. I know this is a common routine that can be done much ...
grayQuant's user avatar
  • 222
5 votes
1 answer
606 views

Compute all valid configuration of eight queens on a 8x8 chess board

Write an algorithm to print all valid ways of arranging eight queens on an 8x8 chess board so that none of them attack any other. Following is my code for this. Do you see any performance or coding ...
Stack crashed's user avatar
1 vote
1 answer
850 views

Compute the number of ways a given amount (cents) can be changed

Given an infinite number of different coin types (such as pennies, nickels, dimes, quarters) find out how many ways n cents can be represented. My code appears to work (although I am curious to ...
Stack crashed's user avatar
10 votes
2 answers
4k views

Generate all valid combinations of n pair of parentheses

Implement an algorithm to print all valid (e.g. properly opened and closed) combinations of n pair of parentheses. Following is my implementation and I think it works. Is the algorithm efficient? Do ...
Stack crashed's user avatar
12 votes
2 answers
5k views

Lovely Lucky LAMBs

I am trying to solve this question from google's foobar. However, my code exceeds the time limit, even though when I tested it I got correct answers. How can I make my code more efficient? Lovely ...
ngmh's user avatar
  • 123
5 votes
5 answers
7k views

Finding large Fibonacci Number in Python

I'm doing Project Euler at 1000-digit Fibonacci number - Problem 25 which says The Fibonacci sequence is defined by the recurrence relation: Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1. ...
user avatar
3 votes
1 answer
1k views

Request for memory optimizations for solution to Google FooBar challenge, "ion_flux_relabeling,"

I just finished one of the Google FooBar Challenges.My Python is super rusty. I did the challenge in Haskell first and then attempted to covert the code. I am guessing that led to some bad Python ...
LambdaScientist's user avatar
2 votes
2 answers
1k views

Project Euler #15 in Python

I've wrote the code for Project Euler #15 and it runs amazingly fast. I know I can write it using binomials but I wanted to calculate by brute force as if I do not know Binomials. But I think it must ...
Gaurish Gangwar's user avatar

15 30 50 per page