All Questions
10 questions
-2
votes
5
answers
212
views
How to check if the substring is present in the parent string in same order
Input
Indian
3
nda
dan
ndani
Output
True
True
False
Explanation
1st line is the parent string
2nd line is the number of test case
The next n lines are the queries
First and Second query substring ...
4
votes
0
answers
330
views
TensorFlow complex loss function "ValueError: No gradients provided.."
I'm trying to implement Dynamic Time Warping as a loss function for a dynamic_rnn() with an LSTMCell(). Basically it's a big loop that fills a matrix, then takes the last value as its score.
In a toy ...
0
votes
0
answers
233
views
grid move algorithm implementation in dynamic programming
Working on below problem,
Problem,
Given a m * n grids, and one is allowed to move up or right, find the different paths between two grid points.
I write two different versions of code, both are ...
0
votes
1
answer
5k
views
How to print the actual Longest Increasing Subsequence, not just length
I am reviewing the GeeksforGeeks code for the Longest Increasing Subsequence and I am trying to figure out how to print the actual longest increasing subsequence, and not just the length.
I know that ...
2
votes
1
answer
604
views
Optimizing this dynamic programming solution
The Problem:
You are given an array m of size n, where each value of m is composed of a weight w, and a percentage p.
m = [m0, m1, m2, ... , mn] = [[m0w, m0p], [m1w, m1p], [m2w, m2p], ..., [mnw, mnp]...
1
vote
3
answers
280
views
how to replace pairwise characters in a string using Python
Suppose I have a string :
x="AAAABBABAABCCABBCA"
and I have the following information :
AAA=1
ABB= ignore/remove from final output
ABA=2
ABC=3
CAB=4
BCA= ignore/remove from final output
so when I ...
0
votes
2
answers
1k
views
Simulating Fibonacci's Rabbits with multiple offsprings using python
Suppose I start with one pair of rabbit and each pair reproduces 3 pairs of rabbits.
Let new rabbit pair be N and mature rabbit pair be M:
N 0
M 1
MNNN 4
MNNN MMM MMM MMM 19
So the series ...
6
votes
4
answers
7k
views
Nth Fibonacci number for n as big as 10^19?
I am trying to make a program to find the nth Fibonacci number for 1 < n < 10^19.
Here is my code using dynamic programming.
memo = {}
def fib(n):
if n in memo:
return memo[n]
...
-2
votes
3
answers
2k
views
Runtime error in python:lists
why is the following code giving runtime error
please suggest the reason, cant the arrays be indexed like c++
t=input()
dp1=[]
dp3=[]
dp5=[]
dp7=[]
dp1[0]=0
dp3[0]=0
dp5[0]=0
dp7[0]=0
dp1[1]=1
dp3[1]=...
2
votes
1
answer
245
views
Dynamic programming - save calculating times
I had an overflow error with this program here!, I realized the mistake of that program. I cannot use range or xrange when it came to really long integers. I tried running the program in Python 3 and ...