Skip to main content

All Questions

Filter by
Sorted by
Tagged with
6 votes
1 answer
990 views

Printing bowTie pattern in efficient and pythonic way

I've posted code/library to GitHub for first time over here. The code is pretty simple. It generates a BowTie pattern of given size and characters. I did attempt to implement DP by calculating only ...
Anil_M's user avatar
  • 163
7 votes
1 answer
298 views

Dynamic Programming with Project Euler problem 67

I am a beginner with python and programming in general. I started teaching myself about 2 months ago. I've been working my way through Project Euler and a few similar sites to build my chops, and ...
M. Guev's user avatar
  • 73
7 votes
2 answers
702 views

Recursive function and memorization to find minimum operations to transform n to 1

I'm a new, self-taught programmer working on the Google FooBar challenge. I've submitted my answer (code at bottom) and it was accepted, but I'd like suggestions on how to improve my solution. ...
user7875185's user avatar
4 votes
1 answer
2k views

Student Attendance Record II

I'm currently working on the Student Attendance Record II problem: Given a positive integer \$n\$, return the number of all possible attendance records with length \$n\$, which will be regarded ...
alecxe's user avatar
  • 17.3k
3 votes
1 answer
248 views

Dynamic programming solution for cross river algorithm (part 2)

I'm working on the cross river problem (previous post here). Any advice on performance improvement in terms of algorithm time complexity, code bugs or code style advice is appreciated. More ...
Lin Ma's user avatar
  • 3,453
5 votes
1 answer
1k views

Dynamic programming solution for cross river algorithm

Working on below cross river problem, and post my code in Python 2.7 using dynamic programming. Any advice on performance improvement in terms of algorithm time complexity, code bugs or code style ...
Lin Ma's user avatar
  • 3,453
4 votes
1 answer
1k views

Guess number with lower or higher hints

Problem statement Two players - Alice and Bob. Alice needs to guess a number \$n\$, from range \$[1, N]\$, \$N \le 200\$ In \$i\$th turn, Alice guesses a number \$i\$ Bob chooses to ...
Lin Ma's user avatar
  • 3,453
4 votes
1 answer
432 views

Different path for grid move

Given a m * n grids, and one is allowed to move up or right, find the different number of paths between two grid points. My major idea is, if move r steps right, <...
Lin Ma's user avatar
  • 3,453
5 votes
2 answers
1k views

High execution time of LCS length program in Python2

I was trying to solve the Longest Common Subsequence problem on a HackerRank exercise. It's quite simple and straightforward, just print out the length of the LCS. I submitted this code: ...
Sidharth Samant's user avatar
2 votes
2 answers
107 views

Find the best path amongst N random points

For an application with a graphical canvas, I want to generate N points. But then I want to link those points, and I want to find the best path through those points. I wanted to use a dynamic ...
clem steredenn's user avatar
2 votes
1 answer
98 views

Optimally allocating a resource with time-varying demand and cost

I'm working on the following DP which finds the optimal way to allocate a resource. At each time step I can either allocate (0.2 resources) at cost C or not in which case the storage is reduced by the ...
ic_fl2's user avatar
  • 123
4 votes
4 answers
12k views

Find the minimum number of coins

I'm trying to learn dynamic programming and the most popular one is to find the minimum number of coins for the change. I come up with this but I just want to improve this code which I think it could ...
toy's user avatar
  • 813