Could you please suggest what I am missing in the code.
Interesting Encoding - One of my test case is failing
Could you please suggest on this doubt ?
Hi give me some time I am debugging the code
please share the hackerblock link for the question
https://online.codingblocks.com/app/player/108835/content/86946/5245/code-challenge
Alice and Bob are planning to send encrypted messages to each other. Alice has decided to assign ‘A’ to code 1, ‘B’ to the code 2,…… ‘Z’ to code 26. Now he wonders given an encrypted message how many different decoding they can form.
Input Format
The first line consists of an integral value denoting number of test cases ‘t’. Then ‘t’ lines follows each containing encrypted string of length ‘n’.
Constraints
1<=n<=5000
Output Format
In each line output the required answer.
Sample Input
1 25114
Sample Output
6
Explanation
25114 can be decoded as ‘BEAN’,‘BEAAD’, ‘YAAD’, ‘YAN’, ‘YKD’, ‘BEKD’.
try using this code
this should solve the problem
actually i cant access the questino not available on hackerblock
if u still get WA do ping back
Its not working all test cases are failing.
send SS
when submitting the code
I have attached the screen-shot of while submitting the solution.
Can we debug the issue in collaboration mode?
public int solve(int pos , int len, String arr, int dp[] ){
if(pos == len) return 1;
if(arr.charAt(pos) == '0') return 0;
if( dp[pos] != -1) return dp[pos];
long ans = 0 ;
ans = solve(pos+ 1, len , arr);
if(pos +1 < len){
if(arr.charAt(pos) == '1') ans+= solve(pos+2 , len, arr);
else if(arr.charAt(pos) == '2' && arr.charAt(pos+1) <= '6') ans+= solve(arr+2 , len, arr);
}
return ans;
}
see this will be the top down approach
and this would run correctly please use proper java syntax ( I have little idea about Java)
and to refer more
Same here i also don’t have much command in c++ . I tried running above given code getting some compile time error.
source.cpp: In function ‘int main()’:
source.cpp:51:20: warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘char (*)[5010]’ [-Wformat=]
51 | while( scanf("%s",&arr)==1 )
| ~^ ~~~~
| | |
| | char ()[5010]
| char
My code is failing for i/p - 1212121212012120
result o/p - 343
Expected o/p - 165
Could you please explain how it’s 165.
If you can somehow dry run
and explain that will be quite helpful.
Hello @chhavibansal - Approach is clear to me. But i am not getting correct answer using that approach or algo. It will be great if you can explain how answer is 165 for above given example.
brooo u have given such a big i/p
its impossible to provide dry run for the same
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.